Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful HTTP response codes

I'm developing a simple RESTful API, and utterly in love with how minimalistic it is. But I'm uncertain as to the correct HTTP response codes for various situations:

  1. Incorrectly formed query

  2. Correctly formed query refers to a resource which does not exist

  3. Resource successfully deleted

  4. Resource successfully edited

I'm currently thinking that 1 would be 403 Forbidden; 2 would be 410 Gone; 3 and 4 would be 202 Accepted. Do they sound right?

like image 658
Marcus Downing Avatar asked May 11 '09 08:05

Marcus Downing


People also ask

What is the 409 response code?

HTTP 409 error status: The HTTP 409 status code (Conflict) indicates that the request could not be processed because of conflict in the request, such as the requested resource is not in the expected state, or the result of processing the request would create a conflict within the resource.

What is REST API responses?

The REST API responds to each request with an HTTP response code. The HTTP standard RFC 2616 is a primary source of information for the meaning of error codes. However, this table provides details of response codes, typical scenarios, and what information can be expected in the response body.


1 Answers

For #1, 403 suggests your application understood the request, but wont fulfil it (i.e. current user doesn't have permission to do that for some reason). I think 400 bad request might make more sense in this case.

For #2 - I would think 404 would make more sense i.e. resource is not found, unless the resource did exist at some point, and has then been deleted, in which case 410 would be fair - but not many clients know what to do with 410.

For #3 & #4 - 200 if you processed the deletion successfully, 202 if the deletion is queued up and will be handled at a later date "out of band".

RFC 2616 provides great explanations of what each response code means in fairly understandable terms.

like image 63
Bittercoder Avatar answered Sep 23 '22 08:09

Bittercoder