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
const article = fetch(`https://dev.to/api/articles?username=${username}`).then((res) => res.json());
Fetch the public Articles by API_KEY
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
)
const article = fetch(`https://dev.to/api/articles/<your_username>/${slug}`).then((res) => res.json());
Fetch the Articles by article_id
const article = fetch(`https://dev.to/api/articles/${articleId}`).then((res) => res.json());
Fetch the Comments of article by article_id
const article = fetch(`https://dev.to/api/comments?a_id=${articleId}?sort=-created_at`).then((res) => res.json());
Fetch the user by user_id
const article = fetch(`https://dev.to/api/users/${userId}`).then((res) => res.json());
Fetch the user by username
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.
Let me know what do you think?