DEV Community

Daniel Newell
Daniel Newell

Posted on

Introducing ForemJS: The API Wrapper for Dev.to

If you hadn't already known, Dev.to has access to an API. You can access it here. For my lovely NodeJS developers, I've started developing an open-souce API wrapper for it called ForemJS.

GitHub logo foremjs / foremjs

A NodeJS wrapper for https://docs.forem.com/api/

Currently, it is very limited but I have plans to cover the entire API. ForemJS runs asynchronously, so you will have to use await, or .then() callbacks. I am currently working on documentation, but here are the basics of how it works.

Step 1 - Install the Package

npm i foremjs@0.1.x

As by SemVer, while the MAJOR version is still 0, breaking changes may occur. The PATCH versions (0.1.x) are going to be adding documentation, and polished up the wrapper as per people's specifications. The next MINOR (0.2.0) version should cover more of the API and get ready for 1.0.0.

Step 2 - Require the Package

const Forem = require('foremjs')

This is a simple process of just requiring the package.

Step 3 - Create a Client

You will have to get a token from your settings page. Now use the following code to create an instance. This is how you will access the API.

const client = new Forem.Client(TOKEN)

Step 4 - Use the API

You can use .getArticle(id) to get an article. These are some of the properties carried by the Article class: .title, .description, and .url. You can see the code for the whole list. There is also .getUser(id), however, it is a bit limited by the API itself. You can get things like .createdAt, and .github for their username.

More features are soon to come, such as posting articles. Thank you so much for reading this article. Maybe my next one will be posted using my wrapper? Seriously, though, if you have any questions, comments, or concerns about this project comment them down below and I will respond as soon as possible.

Top comments (0)