API interaction with a database via CRUD operations
In most web application projects, it is common to work with databases for the purpose of persistent data storage. You won’t be hardcoding plain text into your REST API, unless you are that person who tries to boil the ocean.
CRUD, an acronym for create, read, update, and delete, allows you to manage the state of resources in the database. Interestingly, each of the CRUD elements can also be mapped to the HTTP methods—GET
, POST
, PUT/PATCH
, and DELETE
– which further describes and facilitates the interaction with the database.
In a full stack web application, you expect your users to able to create a resource (POST
or PUT
if it is an existing resource), read a resource (GET
), update a resource (PUT
/PATCH
), and delete a resource (DELETE
). In this section, we will work with a simple venue
resource with the following endpoints, and the HTTP operations we will perform on them are CRUD.
All the code for the...