DEV Community

Cover image for Hey! Did you know Dev.to has an API??
manu
manu

Posted on • Edited on

Hey! Did you know Dev.to has an API??

Have you ever wanted to embed a "Recent Posts" in your website? DEV.to has an API for this.

Check out this example: https://manuthecoder.ml

Just make a simple HTTP request to this URL:

https://dev.to/api/articles?username=____YOUR_USERNAME_HERE____&per_page=5
Enter fullscreen mode Exit fullscreen mode

Example JS usage:

fetch("https://dev.to/api/articles?username=manuthecoder&per_page=10")
  .then(res => res.json())
  .then(res => {
  res.forEach(article => {
    var item = document.createElement("div")
    item.innerHTML = `<b>${article.title}</b><p></p>${article.description}</p>`;
    item.classList.add("card")
    document.body.appendChild(item)
  })
})
Enter fullscreen mode Exit fullscreen mode
  • screw IE. nobody uses it lol

Top comments (2)

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
__manucodes profile image
manu

Yes, indeed!
I was working late at night, and I was a bit lazy....
I could have just used the .text-center class in TailwindCSS