Skip to content

AgathePons/API_base_tools

Repository files navigation

API REST base code to start building an API REST

What is this for?

Propose the base of an app architecture for an API REST with CRUD (Create, Read, Update, Delete) routes.

This app implements various strong and usefull tools to help :

  • Back developer to build the API
  • Front developer to use the API

For the back developer

Clean code

To keep clean and beautiful code, this app propose some NPMs (Node Package Module) in dev dependencies

  • ESLlint file that extends the airbnb config which is one of the most popular
  • Prettier file to formate the code
  • EditorConfig file to help to maintain consistent coding rules across various IDE (integrated development environment)

Logs and debug

To have better logs in console and keep some logs saved in log files

  • debug provides better console logs and allow to toggle the logs for differents parts of the modules
  • bunyan allow to save some logs in JSON

Validate data sent

To validate the data format

  • joi allow to describe data in schemas, and validate the compliance of the data sent.

Handle async/await

In the helpers folder, controllerHandler.js is used with each route which needs async/await. It wraps all the called controllers in a try/catch that allows to lighten the code without include all async/await in try/catch everywhere.

Handle error

A csutom class named ApiError is available to get errors with status code and to throw custom error, with custom message and code.

SQL scripts

2 SQL scripts are provided to create an example database which works with this base app

  • create_tables_example.sql for the DDL (Data Definition Language)
  • seeding_example.sql for the DML (Data Manipulation Language)

For the front developer

Home

pug homepage with link to doc

Documentation using the OpenAPI Specification

About

base architecture for API with some useful tools

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published