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**
- Without API key
 - 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_nameend-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);
});
2. With API key
First we have to generate api key, follow the steps and generate one.
- Logged in to you Dev.to account
 - Go to Settings and then click on Extension or Click Here
 - At bottom you will find 
DEV Community API Keyssection where you have to provide yourproject_nameorname_of_keyand 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);
})
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)