We will create a new RestController annotation called TodoController. The code for the retrieveTodos method is as follows:
@RestController
public class TodoController {
@Autowired
private TodoService todoService;
@GetMapping("/users/{name}/todos")
public List<Todo> retrieveTodos(@PathVariable String name) {
return todoService.retrieveTodos(name);
}
}
A couple of things to note are as follows:
- We are autowiring the todo service using the @Autowired annotation.
- We use the @GetMapping annotation to map the GET request for the "/users/{name}/todos" URI to the retrieveTodos method.