Providing a REST API using Express
Having our data and service layers set up, we have a good framework for being able to write our backend. However, we still need an interface that lets users access our backend. This interface will be a representational state transfer (REST) API. A REST API provides a way to access our server via HTTP requests, which we can make use of when we develop our frontend.
Figure 3.7 – The interaction between client and server using HTTP requests
As we can see, clients can send requests to our backend server, and the server will respond to them. There are five commonly used methods in a REST-based architecture:
- GET: This is used to read resources. Generally, it should not influence the database state and, given the same input, it should return the same output (unless the database state was changed through other requests). This behavior is called idempotence. In response to a successful GET request, a server usually...