@GetMapping
Explore how to implement a @GetMapping REST endpoint in Spring that fetches a list of players from the database, converts Java objects to JSON, and tests the API using tools like Postman and browsers.
Starting from this lesson, we will build a REST service that provides basic CRUD functionality. The client sends an HTTP request to the REST service. The dispatcher servlet handles the request and if the request has JSON data, the HttpMessageConverter converts it to Java objects. The request is mapped to a controller which calls service layer methods. The service layer delegates the call to repository and returns the data as POJO. The MessageConverter converts the data to JSON and it is sent back to the client. The flow of request is shown below:
In this lesson, we will create an endpoint for retrieving the list of players from the database. The REST client will send a request to /players. The REST service will respond with a JSON array of all players.