Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST API POST Response after multiple objects are created?

Tags:

java

rest

jersey

I'm creating tasks with various properties and I'm passing the JSON data from Angular frontend to Java based backend. Assignee is a property of the Task class at the moment. A new request came in to change the behavior: The user should be able to select multiple assignees upon creating a new task.

The way I want to handle this is that I want to create the same amount of tasks as the number of assignees passed. So if n users are passed with the various task data, n tasks would be created in the DB for each user as an assignee.

Previously I could only pass one assignee and the code for returning the POST request's response was the following:

@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 regarding REST design: What should I return as a Result object to the user if multiple objects were created?

like image 567
SLOBY Avatar asked Oct 31 '22 17:10

SLOBY


1 Answers

If a POST request is creating multiple objects, clients will expect back a response entity containing links to each created resource.

like image 90
Eric Stein Avatar answered Nov 15 '22 05:11

Eric Stein