I have a simple server API:
The client can upload a file. The server returns 201 Created
if it was successful. The http response has a Location
header which points to the new created resource.
Now we face a new use case: One http request should be able to create N new resources.
I am unsure how to implement this according to the http spec.
AFAIK there most be only exactly one Location
header.
How to return N URLs in a http 201 Created
response?
My question is related, but not a duplicate of the following question, since the question there is clearly answered with "No". My question is different: How to ...
My question is not "Is it allowed to return several Location header?".
Can the Location header be used for multiple resource locations in a 201 Created response?
The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource.
The 201 HTTP status code means that a request is successful to a resource that was created as a result. The new resource is effectively created before the response code is returned. It is returned to the response message's body.
The response code of 201 is hence a success status code that indicates that a new resource has been created. The new resource is effectively created before this response code is sent back and the new resource is returned to the body of the message.
The origin server MUST create the resource before returning the 201 status code. If the action cannot be carried out immediately, the server SHOULD respond with 202 (Accepted) response instead.
You could take a look at rfc4918, which proposed a new type of response, 207 (Multi-Status), short description copied from REST & WOA Wiki:
A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate. The default Multi-Status response body is a text/xml or application/xml HTTP entity with a 'multistatus' root element. Further elements contain 200, 300, 400, and 500 series status codes generated during the method invocation. 100 series status codes SHOULD NOT be recorded in a 'response' XML element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With