Retrieving a Todo list

We will create a new RestController annotation called TodoController. The code for the retrieve todos method is shown 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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset