Medium is a platform teeming with insightful publications on diverse topics. Suppose you're looking to explore publications related to a specific subject, like "Tech News." Using the medium-api-js
package, you can effortlessly search for publications on Medium.
This guide explains how to achieve that, offering a step-by-step breakdown of the process.
Before diving into the implementation, ensure the following are in place:
medium-api-js
: A wrapper for the Medium API.dotenv
: To manage environment variables securely.npm install medium-api-js dotenv
.env
file in your project directory and add your RapidAPI key:RAPIDAPI_KEY=your_rapidapi_key_here
To search for publications on Medium, follow these steps:
import Medium from 'medium-api-js';
import dotenv from 'dotenv';
Medium
: This is the package used to interact with the Medium API.dotenv
: This package loads environment variables from the .env
file into process.env
.dotenv.config();
This ensures the RAPIDAPI_KEY
from the .env
file is accessible within the script.
const medium = new Medium(process.env.RAPIDAPI_KEY);
The Medium
class takes your API key to authenticate requests.
medium.getSearchPublications('Tech News').then(data => {
console.log('Search Results for Publications:', data);
});
getSearchPublications(query)
: This method fetches publications related to the given query.'Tech News'
.Save the script as getSearchPublications.js
and run it in the terminal:
node getSearchPublications.js
The script returns an object with the search results:
publications
: An array of publication IDs matching the query. These IDs can be used for further exploration.search_query
: Echoes the search term used in the query.In this guide, we explored how to use the medium-api-js
package to search for publications on Medium. By following the outlined steps, you can efficiently fetch publication data for a variety of applications.
For any queries or assistance related to the Medium API, feel free to reach out at nishu@mediumapi.com.