You often forget that APIs exist for most of the platforms you use. While some companies lock down their APIs to only provide very limited information, DEV.to goes the extra mile to provide an extremely robust API. Let’s go over what is available!
Link to Project: https://www.josephamaurer.com/Projects/DevAPI/RecentDevPosts.html
Link to DEV API Documentation: https://docs.forem.com/api/
DEV’s API allows for lots of interesting functionality. In the video above, I go over a use case where you pull the latest 100 posts, and create bootstrap cards for each. In each card I display three buttons. The first is either active or disabled if the user has a twitter account. This is useful because I like to retweet articles and tag their creators. The second button is a link to the DEV post. Finally the third button opens the API response for the article.
While my example showed articles, there are lots of different things that the API can return to you. One of the more interesting functionality is the ability to post an article completely from the API. I have no idea why you would want to do that, but it could be useful.
All in all, it’s cool to think that this functionality exists, even if you can’t find a practical use case for it. One of the more useful use cases might just be populating your recent articles from your blog to your website.
Let me know what you would want to do with this API!
Top comments (9)
First of all, I love the mini app you built for this experiment, as it isn't tied to your followed tags it lets you discover random articles you might not see in your feed! ❤ and 🦄 from me!
As for posting and updating from the API...it is extremely useful if you cross post to other sites. Edit in one place, deploy to many, something I have been piecing together over the last few weeks.
Oh and you can abuse the "update" part of the API to make posts where people can actually add content to them or you can update them automatically (I have two such posts that update every minute to do some fun tricks! Happy to share the links to those and an explanation if that doesn't bother you, but don't want to self promote unnecessarily!)
Oh cool yeah please share a link to what you’re working on! Cool to hear I’m not the only one messing around with the API for fun 😊
dev.to/inhuofficial/i-built-a-3-pa...
In this post I have a "SPA" which has a "contact form" (you will see why I put those in quotes when you play with it / read the article!) - instead of the contact form sending me an email it instead adds anything that is filled in into a comments section within the post itself.
To do that I update the post every minute using the dev.to API based on stored messages (in fact thinking about it it is really inefficient as I do that every minute no matter what, I should change it to just update if a new message has been added....a quick weekend job!)
dev.to/inhuofficial/this-gif-is-ac...
In this article I create a GIF dynamically every minute that counts down to a date.
Yet again the script that creates that GIF runs every minute and then updates the article automatically, that way the GIF is always in sync.
Any questions just ask, but that is my way of getting used to the dev.to API 😋
One thing I did with the API was build a blog generator. It's general purpose if you want to use it as well github.com/winstonpuckett/blog
Also another cool idea for how to integrate everything! I’ve never used a static site generator but this seems like a cool use case 👌🏻
Right? I was actually surprised at how easy it was to add a new feature to that thing. I think I had to break 11ty a bit to get the md to render inside of a page... But it does work for now at least, which is pretty cool :)
Edit: I didn't realize there's no link to the working example lol. Here it is if you're interested - winstonpuckett.com
Ps for some reason the buttons don’t work when viewing the app via the browser in the DEV.to app (iPhone). Fine on desktop, thought I would give you a heads up! (I will try and remember to have a look later to see if I can spot the cause.)
Yeah not sure why but using the buttons when viewing the page within the DEV.to app they won’t open a new window. Using a normal browser like safari or google chrome and they work fine. They might block you from opening new tabs when viewing in the app. Thanks for the heads up 👍🏻