Enhance Your Website with Medium Content: Introducing medium-article-api
How to Fetch and Display Medium Articles Using medium-article-api?
Two years ago, I wrote an article titled “Display Medium Articles on Your Personal Site Using the RSS Feed”. Thanks to Better Programming who published my article. The response from readers was overwhelmingly positive. The article addressed a common need among developers and bloggers to integrate their Medium content seamlessly into their personal websites. Inspired by the feedback and recognizing the ongoing demand for such functionality, I decided to take it a step further. I developed an npm package named ‘medium-article-api’ and published it on npmjs.com along with Misbah Afzal. In this article, I’ll introduce this new package and guide you through its usage.
Why do I need to fetch a Medium feed?
Medium is a third-party platform where you can publish your stories/articles. If you want to show these stories on your site or personal portfolio, you need to fetch the medium stories and display them on your website. It helps you to dynamically integrate the medium with your personal website. So in the future, if you publish any new article, it will automatically display on your site. You don’t need to do redundant work on both platforms.
Introduction
Medium has become a popular platform for writers and developers to share their thoughts, tutorials, and stories. While RSS feeds are a great way to display Medium articles on personal sites, they come with limitations. To provide a more robust and flexible solution, I created the medium-article-api
npm package. This package allows developers to fetch Medium articles and user details effortlessly using the Medium API. This article will walk you through the installation, usage, and benefits of the medium-article-api
.
Our Goal
The aim of this article is to fetch the medium feeds/data without user authentication and display them on your personal site.
Published npm pacakge
https://www.npmjs.com/package/medium-article-api
Installation
To get started, you need to install the medium-article-api
package. Open your terminal and run the following command:
npm install medium-article-api
Usage
Once installed, you can use the package to fetch articles and user details from Medium. Here’s a simple example to get you started:
Fetching User Details and Articles
First, import the package and create an instance of the API client:
import { MediumArticles } from 'medium-article-api';
const mediumArticles = MediumArticles();
const username = '<your-medium-username>';
const profileURL = await mediumArticles.getProfileUrl(username);
Following are the functions available in `medium-article-api`. You can try and use according to your need.
Benefits of Using medium-article-api
1. Ease of Use: The package simplifies the process of fetching Medium data. With just a few lines of code, you can access user details and articles.
2. Flexibility: Unlike RSS feeds, the API provides more control over the data you retrieve, allowing for richer integrations and custom displays.
3. Real-Time Data: By using the API, you ensure that the data displayed on your site is always up-to-date with the latest articles and user information.
4. Enhanced Functionality: The package can be extended to include more features from the Medium API, providing a comprehensive tool for Medium integration.
Conclusion
The medium-article-api
npm package is a powerful tool for developers looking to integrate Medium content into their personal websites. By leveraging the Medium API, it offers greater flexibility and functionality compared to traditional RSS feeds. I encourage you to try out the package and see how it can enhance your site.
If you have any feedback or suggestions, feel free to reach out. Let’s continue to build and share tools that make our development journey smoother and more enjoyable.
Happy coding!
Reference:
Update on 28.05.2024:
The python library for medium is also published on pypi.org named ‘medium-article-py’ . You can follow the usage details in the following links.
PyPi Library: https://pypi.org/project/medium-article-py/
Github Repository: https://github.com/muhammad-usman-108/medium-article-py