My work on the SteemCleaners API: REST overhaul

in #utopian-io6 years ago

Hello! I am @lemony-cricket, and this is my first Utopian contribution! I did some work on the SteemCleaners API originally developed by @howo. I added a big new feature (REST API) and also made some small fixes.



(logo taken from GitHub repository; licence (MIT))


Repository

https://github.com/drov0/sc-api (link to merged pull request)


New Features

REST API

The main new feature is the REST API implementation. The inaugural form of the SteemCleaners API used a single endpoint to process JSON-formatted requests. One of the contributions requested by the maintainer (@howo) was that this be re-worked into a full REST API.

Input

For PUT methods, the REST API accepts data of type application/json containing a single JSON object of the same form as the one returned by a GET request.

  • One exception: if specified, members will be ignored in a PUT to /groups/:group.

Output

Response codes and bodies will be as follows. (Note: this is an image due to Steemit formatting constraints. A text version is available in the README on GitHub.

responsecodestable.png

Endpoints

The following endpoints are available with the methods listed. (Note: this is an image due to Steemit formatting constraints. A text version is available in the README on GitHub.

endpointstable.png

Code Changes

Several changes went into this effort.

  • First, the legacy functionality was broken into several more maintainable files with unique responsibilities. Initially it was all contained within one file. link to commit
  • The database logic was re-written in order to raise exceptions according to what went wrong, allowing for meaningful error messages to be delivered to the client (another improvement requested by the maintainer). link to new source file
  • The authentication logic was reworked to use HTTP Basic authentication. In the prior state, the authentication data was passed as part of the JSON request object. link to commit
  • A nested Express.js router structure was implemented to represent each exposed endpoint.
    • link to new source tree
      • legacy.js contains the legacy API (which is still functional for now).
      • common.js contains common utility functions used by all of the routers (except the legacy one).
      • rest.js and the rest/ directory contain the new REST API.
    • link to example new source file (this one is for the /groups/:group endpoint)

Bug Fixes

  • Fixed an issue where multiple req.send calls could be made on the same request object. In many cases we were not returning after calling req.send which caused a double call and unhandled promise rejection errors in the console.

GitHub Account

https://github.com/lemony-cricket/

Sort:  

thanks for this post

Beyond my understanding but amazing job!

Hi there, thanks for the contribution.


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Hey @lemony-cricket
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.034
BTC 64231.88
ETH 3128.59
USDT 1.00
SBD 3.95