Say that I require a querystring; for example "itemid". If that querystring is for some reason missing, should I give the user a 200 error page or a "404 Not Found"?
I would favour 404 but I'm not really sure.
Say that I require a querystring; for example "itemid". If that querystring is for some reason missing, should I give the user a 200 error page or a "404 Not Found"?
I would favour 404 but I'm not really sure.
Good question. Personally I would use a 200 and provide a user friendly error explaining the problem but it really depends on the circumstances.
Would you also show the 404 if they did provide the itemid but the particular item did not exist?
Give a 500 error, probably a 501. This will allow a browser or code to handle it through existing onError mechanisms, instead of having to listen for it in some custom way.
From a usability standpoint, I'd say neither.
You should display a page that tells the user what's wrong and gives them an opportunity to fix it.
If the link is coming from another page on your site (or another site), then a page that tells them that the requested item wasn't found and redirects them to an appropriate page, maybe one that lets them browse items?
If the user's typing the querystring themselves, then I'd have to ask why? Since the URI isn't typically user-friendly.
Maybe you should give a "400 Bad Request".
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for more possibilities.
And like Chris Simpson said give a "404 Not Found" when no item for the corresponding item id is found.
You could also check popular RESTful apis to see how others have handled the problem. For example Twitter.
You should give a user 200, only when the HTTP Request you got was responded with an appropriate Response, even when it is only a simple HTML that says they are missing a parameter. The 404 code is when the User Agent is requesting a resource that is missing.
Check this list for further info http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
The way I see this working, you should return a 200 - because it should be a valid resource.
Let's say one of your URLs is widgets.com/browse.php?itemid=100
- and that URL displays a specific item in your catalog.
Now, a user enters widgets.com/browse.php
- what do we expect the action to be? To list all of the items in your catalog, of course (or at least a paginated list).
Rethink your URL structure and how directory levels and parameters relate to one another.