Questions tagged [http-status-codes]

HTTP status codes are a set of standardized codes returned in an HTTP web response. Questions about why a service is (unexpectedly) returning a status code should not use this tag.

For a full list of the status codes see the HTTP 1.1 specification, WebDAV specification, RFC 6585, and the IANA list of status codes.

HTTP status codes have specific meanings which are outlined in the specification that they were created in. They can be used in contexts outside of what the specification states, but must adhere to any conditions that have been established in the specification.

1525 questions
3085
votes
17 answers

403 Forbidden vs 401 Unauthorized HTTP responses

For a web page that exists, but for which a user does not have sufficient privileges (they are not logged in or do not belong to the proper user group), what is the proper HTTP response to serve? 401 Unauthorized? 403 Forbidden? Something else? What…
1517
votes
9 answers

HTTP status code for update and delete?

What status code should I set for UPDATE (PUT) and DELETE (e.g. product successfully updated)?
xpepermint
  • 31,091
  • 29
  • 106
  • 160
984
votes
17 answers

HTTP response code for POST when resource already exists

I'm building a server that allows clients to store objects. Those objects are fully constructed at client side, complete with object IDs that are permanent for the whole lifetime of the object. I have defined the API so that clients can create or…
vmj
  • 10,185
  • 3
  • 15
  • 14
891
votes
9 answers

REST HTTP status codes for failed validation or invalid duplicate

I am building an application with a REST-based API and have come to the point where I am specifying status codes for each requests. What status code should i send for requests failing validation or where a request is trying to add a duplicate in my…
alexn
  • 53,351
  • 14
  • 107
  • 142
429
votes
9 answers

What HTTP status response code should I use if the request is missing a required parameter?

I am thinking 412 (Precondition Failed) but there may be a better standard?
EA.
  • 4,560
  • 2
  • 16
  • 13
418
votes
7 answers

What's an appropriate HTTP status code to return by a REST API service for a validation failure?

I'm currently returning 401 Unauthorized whenever I encounter a validation failure in my Django/Piston based REST API application. Having had a look at the HTTP Status Code Registry I'm not convinced that this is an appropriate code for a validation…
michaeljoseph
  • 6,548
  • 5
  • 23
  • 26
402
votes
9 answers

400 vs 422 response to POST of data

I'm trying to figure out what the correct status code to return on different scenarios with a "REST-like" API that I'm working on. Let's say I have an end point that allows POST'ing purchases in JSON format. It looks like this: { …
David S
  • 10,941
  • 10
  • 50
  • 91
260
votes
14 answers

JAX-RS — How to return JSON and HTTP status code together?

I'm writing a REST web app (NetBeans 6.9, JAX-RS, TopLink Essentials) and trying to return JSON and HTTP status code. I have code ready and working that returns JSON when the HTTP GET method is called from the client.…
Meow
  • 16,125
  • 50
  • 122
  • 176
237
votes
14 answers

Returning http status code from Web Api controller

I'm trying to return a status code of 304 not modified for a GET method in a web api controller. The only way I succeeded was something like this: public class TryController : ApiController { public User GetUser(int userId, DateTime…
ozba
  • 6,176
  • 4
  • 30
  • 39
209
votes
5 answers

What is the difference between HTTP status code 200 (cache) vs status code 304?

I'm using the Google "Page Speed" plug-in for Firefox to access my web site. Some of the components on my page is indicated as HTTP status: 200 200 (cache) 304 By Google's "Page Speed". What I'm confused about is the difference between 200 (cache)…
Hank
  • 2,111
  • 2
  • 13
  • 6
186
votes
11 answers

How to specify HTTP error code using Express.js?

I have tried: app.get('/', function(req, res, next) { var e = new Error('error message'); e.status = 400; next(e); }); and: app.get('/', function(req, res, next) { res.statusCode = 400; var e = new Error('error message'); …
tech-man
  • 2,486
  • 2
  • 15
  • 18
180
votes
9 answers

Throw HttpResponseException or return Request.CreateErrorResponse?

After reviewing an article Exception Handling in ASP.NET Web API I am a bit confused as to when to throw an exception vs return an error response. I am also left wondering whether it is possible to modify the response when your method returns a…
zam6ak
  • 6,999
  • 8
  • 42
  • 81
175
votes
3 answers

Python Request Post with param data

This is the raw request for an API call: POST http://192.168.3.45:8080/api/v2/event/log?sessionKey=b299d17b896417a7b18f46544d40adb734240cc2&format=json HTTP/1.1 Accept-Encoding: gzip,deflate Content-Type: application/json Content-Length: 86 Host:…
slysid
  • 4,288
  • 6
  • 28
  • 51
167
votes
8 answers

How do I choose a HTTP status code in REST API for "Not Ready Yet, Try Again Later"?

I'm developing a RESTful API in which http://server/thingyapi/thingyblob/1234 returns the file (aka "blob") associated with thingy #1234 to download. But it may be that the request is made at a time the file does not exist in the server but most…
JCCyC
  • 14,557
  • 11
  • 41
  • 73
161
votes
1 answer

What's the difference between HTTP 301 and 308 status codes?

What's the difference between HTTP 301 and 308 status codes? 301 (Moved Permanently): This and all future requests should be directed to the given URI. 308 (Permanent Redirect): The request and all future requests should be repeated using another…
1
2 3
99 100