I think you are using a specific use case for the Location header. In the case of mass creation, the processing result is usually provided within the returned content itself. In fact, processing can be fully or partially successful. I mean, all elements have been added, or just a subset, and the result shows the end user what is actually happening.
Therefore, I think the Location header cannot be used in this context. I see two options for the status code:
- Status code 201 , if at least one item is created)
- Status code 200 to indicate that the bulk request request is executed globally, but the result of each operation is described in the response content.
However, you may notice that there is a 202 status code if your resource handles bulk creations in an asynchronous way. But in this context, you need to pull the resource to get the status of the inserts.
Regarding the content of the answer, you are free to choose. We could imagine something like this:
{ "took": 4, "errors": true | false, "items": [ { "added": true, "error": null "id": "123" }, { "added": false, "error": { "code": "err12", "description": "validation error (field type, ...)" } "id": null } ] }
ElasticSearch provides such an api array for creation, but also supports updating and deletion. See this link for more details: http://www.elastic.co/guide/en/elasticsearch/guide/current/bulk.html p>
Here are some similar questions that may give some clues:
Hope this helps you, Thierry
source share