asingh
asingh

Reputation: 3

Can GET request message ever return a HTTP status code of 201?

Can a GET request message ever return a HTTP status code of 201?

Upvotes: 0

Views: 2429

Answers (3)

Evert
Evert

Reputation: 99553

A conforming HTTP server should never do this. GET is a safe method, and is not supposed to have any side effects.

201 means a new resource was created on the server, which really is a side-effect.

So if a GET results in a 201, something is wrong. However, if you are building a client want to know in advance which success codes you might get, you should simply support every code between 200 and 299 (inclusive) and treat them all as success codes.

Upvotes: 3

JBallin
JBallin

Reputation: 9787

Yes. The API has control over what status code to send.

In practice, the status code is meant to communicate the status of the response - so it’s unlikely that a 201 (“Created”) should be returned from a GET request.

Upvotes: 1

Huy Ha
Huy Ha

Reputation: 82

201 - created.

We can return code 201 for GET, but normally we use POST to send some data in server. So I don't think it is good to return 201 for GET

Upvotes: -1

Related Questions