Issue
i'm constructing a web-service that is used, in this particular case, to ask for information about a patron.
Let's say, for the sake of argument, that the lookup web hit is:
GET /patrons/619 HTTP/1.1
If the patron is found, i return code 200:
HTTP/1.1 200 OK
If you omit, or give an account number that is not a number, i return 400. For example the following bad requests:
GET /patrons HTTP/1.1
GET /patrons/ HTTP/1.1
GET /patrons/qwerty HTTP/1.1
GET /patrons/kylie%20guenin HTTP/1.1
all return error 400 (Bad Request), e.g.:
HTTP/1.1 400 Invalid patron number
i want to have a status code for patron not found, returned as the HTTP status code. For example:
GET /patrons/1322 HTTP/1.1
HTTP/1.1 404 Not Found
i've thought about using 404 (Not Found), which is a valid response (the requested resource was, really and truely, not found.) But i'm afraid people debugging it might think that it means that they spelled /patrons/
wrong.
Can anyone think of another http status code i could use?
Update: i'm eyeballing
204 No Content
The server successfully processed the request, but is not returning any content.
What say you?
Don't forget, that not all HTTP servers serve up HTML content. If an IIS web-server is asked for a resource called:
GET /MyStartPage.html HTTP/1.1
Then the HTTP server has to decide what to respond with. On most web-servers, a resource named /MyStartPage.html corresponds to a file sitting on the hard drive.
Whereas StackOverflow does:
GET /posts/1027301 HTTP/1.1
Which, if that resource doesn't exist, the web-server should (rightly) return 404.
Solution
404 Not Found is the correct thing to return, if it's a service, it's not really being used by humans but by machines, and therefore, typos, shouldn't be your first concern.
Also, there's very little you're going to be able to do to counter human behavior anyway (thinking one thing when it's really another). If you're returning a little error msg as part of the error code, everything should work out. You could even suggest to them a possible fix.
Returning a 500 when the application is doing exactly what it's designed to do also seems a little odd. 404 describes exactly the situation: Resource not found.
Answered By - cgp Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.