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. Add the dependencies jakarta.servlet-api and jackson-databind as well as the maven-war-plugin to the Maven project, and change the packaging type to war.
  3. Implement the TodosServlet that uses the todo service to support the following REST requests regarding all todos (see also OpenAPI specification):
    • GET /api/todos returns all todos
    • GET /api/todos?category={category} returns the todos of the specified category
    • POST /api/todos adds a todo (whose data is defined by the TodoCreateDto record)
    Make sure to return appropriate status codes, especially in case of error.
  4. Implement the TodoServlet that uses the todo service to support the following REST requests regarding a single todo (see also OpenAPI specification):
    • GET /api/todos/{id} returns the todo with the specified identifier
    • PUT /api/todos/{id} updates the specified todo
    • DELETE /api/todos/{id} deletes the specified todo
    • (Optional) PATCH /api/todos/{id} changes the completion status of the specified todo
      (as defined by the TodoCompleteDto record)
    Make sure to return appropriate status codes, especially in case of error.
  5. Create an ObjectMapper using the ObjectMapperFactory and use it to convert Java objects to JSON and vice versa.
  6. Use the Postman application to test the REST service.
  7. (Optional) Implement the CategoriesServlet which returns the possible todo categories in response to the REST request GET /api/categories .
  8. (Optional) Verify that the media type headers Content-Type and Accept are set correctly and return an appropriate error response if not.
Solution