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?
Top comments (6)
From where we can find api-key ?
You can find it in Settings > Extensions.
Thanks for the post. I was struggling to make it work due to the fact that the docs just show examples by using
curl
. I don't see much info about the API key and the request limit. Do you know how to use the API key for this case? And if there is a gain in rate limit by using it?To use the api key you can do like this -
this example is just to fetch your blogs data with
API_KEY
.Hi, i'm kind of new here, do you know how long it takes to add a new article (post) on the API?
I've never published one thorough API, but I don't think it takes too much time, just a few seconds maybe. There is no timing mentioned in the dev.to API documentation