DEV Community

Cover image for Use of Dev.to API using NodeJS and Axios
Snehal Rajeev Moon
Snehal Rajeev Moon

Posted on

Use of Dev.to API using NodeJS and Axios

Hello Reader,

Here we will discuss how we can access Dev.to API using NodeJS and axios.

I will show you how we can achieve that**

  1. Without API key
  2. With API key.

Here you can get more details about dev.to api API Documentation
So, let's dig into it.

1. Without API key

  • First install axios using nodeJS and write the bellow code by passing the username to the this https://dev.to/api/articles?username=your_name end-point to get user's articles.
const axios = require('axios');

let configDetails = {
  method: 'get',
  url: 'https://dev.to/api/articles?username=snehalkadwe',
  headers: { 
    'Content-Type': 'application/json'
  }
};

axios.request(configDetails)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});
Enter fullscreen mode Exit fullscreen mode

2. With API key

First we have to generate api key, follow the steps and generate one.

  1. Logged in to you Dev.to account
  2. Go to Settings and then click on Extension or Click Here
  3. At bottom you will find DEV Community API Keys section where you have to provide your project_name or name_of_key and click on generate api key, your key will be generated.

Now, we have to pass api key and content-type in header with this https://dev.to/api/articles/me end-point to grab articles.

Add this code.

const axios = require('axios');

let configDetails = {
  method: 'get',
  maxBodyLength: Infinity,
  url: 'https://dev.to/api/articles/me',
  headers: { 
    'Content-Type': 'application/json', 
    'api-key': 'ADD_YOUR_API_KEY'
  }
};

axios.request(configDetails)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
})
Enter fullscreen mode Exit fullscreen mode

In both the ways you can get all the latest articles and posts in your system. For more details you refer dev.to api documentation and try to use different end-points.

❤️ Thank You!! ❤️

Happy Reading ❤️ 🦄

Top comments (0)