[ad_1]
I have created my own portfolio and described what it has in a previous article. In this article, I will show how I use DEV Community API to fetch articles that I have published.
Get API
Like every API, you need to get your API key first.
-
Go to your settings/extensions pages
-
Find the section name “DEV Community API Keys” at the end and fill the description with every text you want (ex: Expose Article), click button to generate API key
-
It will generate the collapsed item below, exposing it to get the key
Get published articles
After you got API key, you can use the code below to get the data
/**
* Get published articles.
* @param {number} page_size - the number of items to return per page.
*/
function fetch_articles(page_size = 7){
// Build URL
const base_url = "https://dev.to"; // domain
const router = "api/articles/me"; // API router
const url = `${base_url}/${router}?per_page=${page_size}`; // https://dev.to/api/articles/me/published?per_page=7
// Get data from API
const response = await fetch(url, {
headers: {
"Content-Type": "application/json",
"API-Key": "Your Key Is Here",
},
}).then((data) => data.json());
return response;
}
Conclusion
So that is the way I use DEV Community API to get published articles. In the next article, I will write about why and how I combine Google Sheets + Google Drive to save my pet projects
Happy Coding!
[ad_2]
Source link