Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the Location header be used for multiple resource locations in a 201 Created response?

Tags:

rest

http

What is the correct verb and response to accept a batch PUT create and then return multiple locations? The Location header only appears to support one single Uri.

I assumed originally I could use PUT for a batch create and return an string array with a list of Uris, but in looking at the specification, that doesn't appear to be supported, but it isn't entirely clear either.

Are multiple Location headers permissible as an alternative?

Any advice?

like image 338
Rebecca Avatar asked Jul 03 '12 10:07

Rebecca


People also ask

What is Location header used for?

The Location response header indicates the URL to redirect a page to. It only provides a meaning when served with a 3xx (redirection) or 201 (created) status response.

Which header should client use in response for information about newly created resource?

After a resource has been created successfully, the server should respond with HTTP 201 (Created). The response should also have a Location header that contains the URI of the newly created resource. When needed, the response body can contain the created resource. In this case, a Content-Type header is also required.

What is Location header in REST API?

The Location response header's value is a URI that identifies a resource that may be of interest to the client. In response to the successful creation of a resource within a collection or store, a REST API must include the Location header to designate the URI of the newly created resource.

What is HTTP Location header?

The HTTP Location header is a response header that is used under 2 circumstances to ask a browser to redirect a URL (status code 3xx) or provide information about the location of a newly created resource (status code of 201).


1 Answers

No, you can have only one Location header field (and yes, it is clear from the spec).

That being said, PUT is for creating/updating a single resource. It seems that you're using it for something it is not designed for...

like image 100
Julian Reschke Avatar answered Oct 28 '22 11:10

Julian Reschke