Spring Web Services

Exercise: Todo REST Service

The objective of this exercise is to implement a RESTful Todo Web Service using Spring Web MVC.

Assignment

  1. Preparation
    • Remove the client artifacts from the todo application
    • Add the spring-boot-starter-web dependency to the Maven project
  2. Service implementation
    • Make the TodoListImpl class a REST controller by annotating it with Spring Web MVC annotations
    • Replace the multiple parameters of the addTodo method by a single todo object
    • Add an ID path variable to the updateTodo method and verify its consistency
    • Implement an exception handler for the TodoNotFoundException such that the error status 404 and an appropriate problem detail is returned when the exception is thrown
  3. Configuration
    • Set the spring.mvc.problemdetails.enabled application property to enable support for problem details (RFC 7807)
    • Define the server.servlet.contextPath application property to customize the URL pattern of the DispatcherServlet (e.g. /rest)
  4. Testing
    • Use the Postman utility to send REST requests the web service

Solution