Designing and building the API
Before writing the code, we need to have a neat idea in mind of the resources we are going to make available through the API, the methods we will provide to manipulate such resources, and the response codes we will deliver to the clients. After designing the API, we can start write some code to implement resources representation.
Resources, URLs, HTTP verbs, and response code
Defining a resource is very similar to defining a model class in an ORM system, and it's not uncommon for them to coincide, like in our case. In fact, we will provide the following resources:
Note
NoteFile
ChecklistItem
Every resource will be identified by a URL. We omit the hostname here for clarity:
The
/notes
URL: This identifies a collection of resources of type NoteThe
/notes/:id
URL: This identifies a single resource of type Note using its ID as the discriminatorThe
/notefiles
URL: This identifies a collection of resources of type NoteFileThe
/notefiles/:id
URL: This identifies a single...