Search⌘ K
AI Features

Elite Club Search Web Service

Explore how to expose RESTful web services in Spring Boot by creating CRUD and search endpoints for the Elite Club application. Understand the correct HTTP methods to use, the difference between URI and query parameters, and the challenges of REST design. Gain practical skills in building resource-oriented APIs aligned with REST principles.

Objective

In this chapter, we will expose the REST endpoint for the CRUD and search operation in the Elite Club application.

Elite club APIs

We saw how easy it is to create a Restful web service using Spring Boot. We will be exposing the following methods over HTTP.

URI HTTP Method Description
/club GET Get all clubs
/club/{id} GET Get one club with requsted id
/club/{id} DELETE Delete club with requsted id
/club POST Create new club
/club/{id} PUT Modify club with requested id
/club/serach?searchTerm=? GET Search club with search term

Add a club

We already have business logic to add a club into DB available into our service EliteClubService.java

To expose the RESTendpoint for this operation we need to identify the correct HTTP verb to be used. If we _think of the club _ as a resource, then adding a club is nothing but creating a resource.

The obvious choice is to use HTTP POST. The POST endpoint will look like the following code snippet:

@PostMapping(path = "/club", produces = MediaType.APPLICATION_JSON_VALUE)
   
...