Create Your Own Blog with DevTO API
I joined DevTO since June 2019. It's quite an interesting platform where programmers share ideas and help each other grow. It is an online community for sharing and discovering great ideas, having debates, and making friends. Anyone can share articles, questions, discussions, etc. as long as they have the rights to the words they are sharing. Cross-posting from your own blog is welcome - quote from the About page.
I wrote a few posts on the platform and I actually like it. And more intriguing, I discovered their API (beta version), which allows me to get the articles in JSON format.
I knew that I can to put all the posts from DevTO to my newly rebuilt website. And there are some challenges that need to be resolved:
- How should it look like on my website?
- How can I display the "all the post" page?
- How can I display the article page?
Fortunately, I have everything in mind, and I already put them into action. Here is how I did it with Angular, and you can do with any framework you prefer.
How should it look like on my website?
I try to make it simple and readable on every different device. You can do some research and decide how do you want to style your own blog.
How can I display the "all the post" page?
The endpoint where I can get all the articles is Published articles. With the parameter "username", I can return all the articles written by me.
https://dev.to/api/articles?username=dalenguyen
For the content, getting the JSON from the API is pretty easy with HttpClient.
Then show it with Angular Material
How can I display the article page?
This is the tricky part because I will need to make another request in order to get the content of a single post - and the id is used for this purpose.
and for the HTML part
For embedded URLs from the article, how can I deal with it? If I just leave it, I will lead to DevTO website, and I really don't want that. So before serving the HTML to the front end, I have to replace the domain name from DevTo to my website.
From now, you can create your own blog which the content from DevTO - it will take a few hours until the article can be shown on your website. You can find the project from my Github account.