API documentation

When you are working on a real project, the number of endpoints you will need to design will be higher. You will need a way to remember all your endpoints and the reason they were designed. Similarly, we are confident that documenting software is extremely important for us to remember what a piece of code is supposed to do; API documentation allows us to tell the API consumers how they can use our API by documenting the endpoints and other additional metadata, such as the ones listed:

  • Endpoint path
  • HTTP verbs
  • The expected headers
  • The expected body structure
  • The expected results
There is an awesome open source tool that helps you document and share the documentation with your APIs called Swagger. We encourage you to visit the official site and play with it at https://swagger.io.

A possible documentation might be just a simple table that contains the data used in the request and responses. For example, the documentation to create a new product might be this:

Path Products
HTTP method POST
Expected Results HTTP 200 OK status code
Expected Input Headers Content-type: application/json
Expected Input Body {id: Integer, name: String, price: Decimal}
Goal Use this endpoint to create a new product
Authorization Required Authorization Token

 

Having the knowledge of how to design self-explained APIs and how to use HTTP to create endpoints, let's move forward to implement a RESTful API with Node.js.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset