V
V
Vyacheslav Slinko2012-10-16 01:20:16
API
Vyacheslav Slinko, 2012-10-16 01:20:16

How to make a redirect in the browser after creating a resource with HTTP code 201 Created with RESTful API?

When I receive a request POST /resources/, I send a response.

HTTP/1.1 201 Created
Location: /resources/1

In the case of xml or json, everything is fine - the code 201 and the description of the resource in the response.
But in the case of a browser, everything is bad - this response does not lead to a redirect, and giving a description of the resource by the link /resources/(to which the POST request came) is not good.
I see several options:
  1. return a 302 code to the browser;
  2. still give a description of the resource in the response;
  3. use ajax for all POST and PUT requests.

How are you doing?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2012-10-16
@KeepYourMind

www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30

For 201 (Created) responses, the Location is that of the new resource which was created by the request.

A
Alexey Huseynov, 2012-10-16
@kibergus

Give the created resource in the response body.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question