REST API Design
Learn about the basic design principles for a REST API and start creating one using Spring Initializr.
In this lesson, we will start building a REST API that performs CRUD operations. We will make use of the tennis player project (created in the Spring JDBC and Spring Data JPA chapters) to create a REST API to perform CRUD operations on the data stored in the in-memory H2 database.
REST API design
Our REST API will expose endpoints which allow a REST client to perform the following functions:
Get a list of players
Get a player by ID
Add a new player
Update an existing player
Update the titles of a player
Delete a player
We will make use of the HTTP GET, POST, PUT, PATCH, and DELETE methods to perform these operations. To create service endpoints for our REST API, we need to identify the entity (main resource) which is the most notable noun from the requirements listed above. A glance at our requirements shows that it is player. A REST API design convention is to use the plural of the entity as the endpoint, so we will use /players.
The following image shows the HTTP methods and their REST endpoints for the corresponding CRUD operations:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.