How to use the dev.to API?

Jatin Sharma

Jatin SharmaOct 19, 2021

2 min read242 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.

Learn How to use fetch()

Jatin's Newsletter

Get notified in your inbox whenever I write a new blog post.

Share on Social Media: