简体   繁体   English

创建多个对象后的REST API POST响应?

[英]REST API POST Response after multiple objects are created?

I'm creating tasks with various properties and I'm passing the JSON data from Angular frontend to Java based backend. 我正在创建具有各种属性的任务,并且我将JSON数据从Angular前端传递到基于Java的后端。 Assignee is a property of the Task class at the moment. 受让人目前是Task类的属性。 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. 因此,如果n个用户与各种任务数据一起传递,则将在DB中为每个用户创建n个任务作为受让人。

Previously I could only pass one assignee and the code for returning the POST request's response was the following: 以前我只能通过一个受让人,返回POST请求的响应代码如下:

@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? 我的问题是关于REST设计: 如果创建了多个对象,我应该将什么作为Result对象返回给用户?

如果POST请求正在创建多个对象,则客户端将期望返回包含指向每个已创建资源的链接的响应实体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM