Web Programming

Todo REST Service (Interface)

The objective of this exercise is to implement a REST interface of a todo service.

Tasks

  1. Clone the GitLab repository Todo REST Service.
  2. Implement the servlet TodosServlet that uses the todo service to support the following REST requests regarding all todos (see also OpenAPI Definition):
    • GET /api/todos returns all todos
    • GET /api/todos?category={category} returns the todos of the specified category
    • POST /api/todos adds a todo
    Make sure to return appropriate status codes, especially in case of error.
  3. Implement the servlet TodoServlet that uses the todo service to support the following REST requests regarding a single todo (see also OpenAPI Definition):
    • GET /api/todos/{id} returns the todo with the specified identifier
    • PUT /api/todos/{id} updates the todo with the specified identifier
    • DELETE /api/todos/{id} deletes the todo with the specified identifier
    Make sure to return appropriate status codes, especially in case of error.
  4. Use the factory ObjectMapperFactory to create a Jackson ObjectMapper and use it to convert Java objects to JSON and vice versa.
  5. (Optional) Verify that the media type headers Content-Type and Accept are set correctly and return an appropriate error response if not.
  6. (Optional) Implement the servlet CategoriesServlet which returns the possible todo categories for the REST request GET /api/categories .
  7. Use the Postman application to test the REST service.



Solution