Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Status 201 Created: Return N URLs to the new resources?

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?

like image 955
guettli Avatar asked Dec 18 '17 08:12

guettli


People also ask

What is the HTTP status code 201 indicates?

The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource.

Should a post request which returns 201 return the resource in the body?

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.

When should we use status code 201 to respond?

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.

Which HTTP status code is usually returned when a resource was found and returned?

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.


1 Answers

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.

like image 193
georgexsh Avatar answered Sep 23 '22 20:09

georgexsh