user331465
user331465

Reputation: 3094

How should client of Restful API handle http status 301 redirect upon POST?

Question

How should a well-designed application handle 301 "moved permanently" redirects upon http POST to restful api?

Context

I know that "restful api's should be permanent", but, merde arrive (that's shit happens in French)--Empires crumble, Berlin Wall falls, Oracle buys Sun etc.

The Problem

Their application makes HTTP post calls to our restful api. When the front end returns 'http status 301', their application does not 're-post' to the new url, and the update fails.

Questions

Upvotes: 12

Views: 11966

Answers (1)

Palpatim
Palpatim

Reputation: 9262

To fulfill your "well-designed" requirement in the sense of "pure RESTfulness", the client should re-send the request to the new URI. A response code of 301 indicate the resource has moved, and cannot be used to fulfill the request, so there's really no fallback position.

If the client attempts to re-post, but loses data, that's a client bug. The "correct" behavior of a client varies by your requirements: it could treat the redirect as a recoverable error case, and repost transparently; it could repost while instructing the user to update the endpoint; or it could fail with an appropriate error message.

Upvotes: 8

Related Questions