Creating a REST Controller

Learn how to create a controller to map requests to our REST API.

In this lesson, we will create a REST service with a request mapping /welcome and send it a request from a REST client (web browser or Postman). The service will respond with a welcome message.

1. @RestController

The first step is creating a controller class called PlayerController with the @RestController annotation. This annotation is an extension of @Controller annotation. The @RestController annotation has support for REST requests and responses and automatically handles the data binding between the Java POJOs and JSON.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.