Search⌘ K

Develop the REST Controllers

Explore how to develop REST controllers in Spring to handle CRUD operations on resources with annotations such as @GetMapping, @PostMapping, @PutMapping, and @DeleteMapping. Understand how to expose API endpoints that process JSON responses and enable interaction with REST APIs using tools like cURL.

Create REST controller

Create the TodoTypeController class in the io.educative.controllers package to work as a REST controller.

Java
package io.educative.controllers;
import org.springframework.web.bind.annotation.*;
@RestController //define TodoTypeController as REST controller
@RequestMapping("/api/todoType") //expose the REST endpoints at /api/todoType
public class TodoTypeController {
}

In the above code section, we see the following annotations that help expose the REST APIs:

  • The @RestController annotation combines the @Controller and @ResponseBody annotations to mark the class as a request handler and
...