PROGRAMMING

Unofficial Medium API: Get Posts Using Node.js

Using "Axios" library ...

Image by the Author

As a data engineer, I always have to be on the lookout for new sources of data and efficient ways to handle them.

After spending so much time on Medium, I can say this with absolute certainty that Medium is an incredible source of textual data - From author-related info to the wide variety of articles present, there's a lot of data available for us to work with.

But manually extracting this data from Medium and copy/pasting is an error-prone and time-consuming process. If you need to scrape millions of pages, it's not possible to do it manually.

That's why, I recently built the Unofficial Medium API, about which I discussed thoroughly in my recent articles. By using Unofficial Medium API, you can do this data extraction process in the blink of an eye.

Today, I'm going to use Node.js, whose development has become very popular over the last four years and continues to stand the competition in 2022, to extract data from Medium.

Using Node.js and Axios, which is a promise-based HTTP Client for Node.js, we are going to walk through a simple process of fetching posts from Medium with Medium APIs.


Prerequisite -

  1. Install Node.js
  2. Install Axios (npm install axios)
  3. Register to RapidAPI to get YOUR_APIKEY (It won't take long, trust me!)

Code in Steps -

  1. Import Axios package and set preliminary variables

2. To ease up the multiple (and repetitive) calling through Axios (with more or less the same functional code), let's write a small method that we'll use -

3. Now we're ready to use our API - First, get the user_id.Second, get the article_ids for the user, and third, fetch each article written by the user. That's it.

The output of the first article's info -

Full Code -


Help & References -

In case you're stuck somewhere, read the following articles for more information -

Or you can contact me, I would be happy to help ...

nishu@mediumapi.com

Thanks for reading and have a nice day!