Specifying the API

The very first thing a project usually starts with is a definition of the operations the API will expose. According to the REST principles, an operation is exposed by an HTTP method and a URI. The action performed by each operation should not contradict the natural meaning of its HTTP method. The following table specifies the operations of our API in detail:

Method URI Description
GET /category Retrieves all available categories in the catalog.
GET /category/{category-id}/ Retrieves all the items available under a specific category.
GET   /category/{category-id}/{item-id}  Retrieves an item by its ID under a specific category.
POST /category

Creates a new category; if it exists, it will update it.

POST 

Get RESTful Web API Design with Node.js 10 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.