REST API POST Answer after creating multiple objects?

I create tasks with various properties and I pass JSON data from a Java based Angular interface. Assignee is a property of the Task class at the moment. To change the behavior, a new request appeared: the user should be able to select several assignees when creating a new task.

The way I want to deal with this is that I want to create the same number of tasks as the number of rights transferred. Therefore, if n users are transferred with different task data, n tasks will be created in the database for each user as a successor.

Previously, I could only transfer one successor, and the code to return a response to a POST request was as follows:

@POST @Consumes(MediaType.APPLICATION_JSON) public Response save(TaskInDto taskInDto) { // saving to DB, etc... String taskId = createdTask.getId().toString(); URI taskUri = uriInfo.getAbsolutePathBuilder().path(taskId).build(); return Response.created(taskUri).build(); } 

My question is about REST design: What should I return as a Result object for the user if multiple objects have been created?

+5
source share
1 answer

If a POST request creates multiple objects, clients will expect a response object back containing links to each created resource.

+2
source

Source: https://habr.com/ru/post/1201837/


All Articles