How to Get Top Feeds from Medium

Using the Medium API in JavaScript

If you want to extract Medium's top articles for a specific tag programmatically, the Medium API is your go-to solution.

This article will guide you through how to fetch top feeds for a given tag and mode using JavaScript. By the end of this guide, you'll have a clear understanding of the code implementation, its output, and its potential applications.

Prerequisites

Before diving into the implementation, make sure you have the following:

Code Explanation

The code leverages the medium-api-js package to fetch the top feeds for a specified tag and mode. Here's a detailed breakdown:

Step 1: Import Required Packages

import Medium from 'medium-api-js';
import dotenv from 'dotenv';

dotenv.config();

Step 2: Configure the Medium Instance

const medium = new Medium(process.env.RAPIDAPI_KEY);

The Medium instance is initialized with the API key, which is stored in the environment variable RAPIDAPI_KEY. Make sure to create a .env file with the following content:

RAPIDAPI_KEY=your_api_key_here

Step 3: Fetch Top Feeds

medium.getTopFeeds('data-science', 'NEW')
    .then(data => {
     console.log('Top Feeds:', data);
    });

Running the Code

To execute the code:

  1. Save the code to a file named getTopFeeds.js.
  2. Run the following command in the terminal:
  3. node getTopFeeds.js

Output

The output displays the top feeds for the specified tag and mode:

Explanation

Potential Use Cases

Summary

Fetching top feeds from Medium using the Medium API is both simple and powerful. This article demonstrated how to retrieve curated content for specific tags and modes, enabling diverse applications like trend analysis and personalized content delivery.

If you have any questions about the Medium API or need further assistance, feel free to reach out to me at nishu@mediumapi.com.

nishu@mediumapi.com