Should I stop redirecting after successful POST or PUT requests?

Typically, the Rails community typically responds to successful requests POST, PUTor DELETEby redirecting instead of returning. For example, if I am PUTa legal change in my user profile, then the idiomatic response will be 302 Redirecton the profile page.

Is that not so? Shouldn't we return 200 OKfrom the request? Or a 201 Created, in case of a request POST? Any of these, in the HTTP / 1.1 Status Definition , is allowed (or should) include a response, in any case.

I think I’m wondering, before I go and “fix” my application, is there a damn good reason why the community switched to redirecting instead of successful answers.

+5
source share
3 answers

, PUT, , -, . POST post-redirect-get, , . , , , , , . , , , HTTP.

+4

POST-Redirect-GET (PRG). () idempotent, , .

-, RoR. , .

+2

In an ideal world, yes, probably. However, HTTP clients and servers are messy when it comes to standardization, and don't always agree on the right protocol. Redirecting after publishing helps avoid things like duplicate forms.

0
source

All Articles