Java Web Applications
Todo REST Service (Interface)
The objective of this exercise is to implement a REST interface of a todo service.
Tasks
-
Extract the template project todo-rest-service.zip.
-
Implement the servlet
TodoListServlet that holds a global todo list and supports the following REST requests
(see also OpenAPI Definition):
GET /api/todos returns all todos of the list
GET /api/todos?category={category} returns the todos of the specified category
GET /api/todos/{id} returns the todo with the specified identifier
POST /api/todos adds a todo to the list
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.
-
Use the factory
ObjectMapperFactory to create an object mapper and use it to convert Java objects to JSON and vice versa.
-
(Optional) Verify that the media type headers
Content-Type and Accept are set correctly and return an appropriate error response if not.
-
Use the Postman application to test the REST service.
Solution