Table of Contents
How to use the dev.to API?
Oct 8, 2021
2 min read
242 words
Why do we need to use it ?
In this article I am only covering the article API of Dev.to. we can use this API for our personal portfolio website. Think like you are building a portfolio website and you need to show your blogs from Dev.to in your portfolio so this API comes into play.
How to use it?
I'm using the vanilla JavaScript to show the demo you can use axios
as well.
Fetch the public Articles without API_KEY
script.js
const article = fetch(`https://dev.to/api/articles?username=${username}`).then(
(res) => res.json()
);
Fetch the public Articles by API_KEY
script.js
const articles = fetch("https://dev.to/api/articles/me", {
headers: {
"api-key": process.env.API_KEY,
},
}).then((res) => res.json());
Fetch the Articles by Path (slug
)
script.js
const article = fetch(
`https://dev.to/api/articles/<your_username>/${slug}`
).then((res) => res.json());
Fetch the Articles by article_id
script.js
const article = fetch(`https://dev.to/api/articles/${articleId}`).then((res) =>
res.json()
);
Fetch the Comments of article by article_id
script.js
const article = fetch(
`https://dev.to/api/comments?a_id=${articleId}?sort=-created_at`
).then((res) => res.json());
Fetch the user by user_id
script.js
const article = fetch(`https://dev.to/api/users/${userId}`).then((res) =>
res.json()
);
Fetch the user by username
script.js
const article = fetch(
`https://dev.to/api/users/by_username?url=${username}`
).then((res) => res.json());
So basically this is all we need to fetch the Dev.to API.
Jatin's Newsletter
I write monthly Tech, Web Development and chrome extension that will improve your productivity. Trust me, I won't spam you.