Web Programming
Todo REST Service (Interface)
The objective of this exercise is to implement a REST interface of a todo service.
Tasks
-
Clone the GitLab repository Todo REST Service.
-
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.
-
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.
-
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.
-
Create an ObjectMapper using the ObjectMapperFactory and use it to convert Java objects to JSON and vice versa.
-
Use the Postman application to test the REST service.
-
(Optional) Implement the
CategoriesServlet which returns the possible todo categories in response to the REST request GET /api/categories .
-
(Optional) Verify that the media type headers
Content-Type and Accept are set correctly and return an appropriate error response if not.
Solution