0

Given we have a web service that takes numerical identifiers. What is the generally most agreed upon HTTP Status Code for an invalid (non-numerical) identifier?

Valid Resource Identifier

Request: GET http://service.co.uk/resources/123

Response: 200 OK

Valid but Unknown Resource Identifier

Request: GET http://service.co.uk/resources/456

Response: 404 Not Found

Invalid Resource Identifier

Request: GET http://service.co.uk/resources/abc

Response: 400 Bad Request

In the event of an invalid identifier, 404 (Not Found) accurately describes the situation; we failed to locate the resource. However 400 (Bad Request) gives an indication as to why the resource was not found.

RFC 2616

10.4.1 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.

10.4.5 404 Not Found

The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.

2
  • 400 Bad Request is most appropriate but this question is likely to be closed because it's very opinion related. Commented Aug 25, 2014 at 8:46
  • @DanFromGermany Its a bad request in the domain of the application logic which dictates that non numerical identifiers are invalid. But as the RFC states about 404 "The server has not found anything matching the Request-URI". Commented Aug 25, 2014 at 8:48

1 Answer 1

0

That URL is not syntactically incorrect, it's semantically incorrect. It has the correct grammar/structure, but the specific identifier chosen doesn't make any sense. That makes 400 (Bad Request) a bad candidate. If it were /123/resources, you might argue that it's syntactically incorrect, but I bet your framework will reply with a 404 for any paths you don't specify. Even if both were applicable, you should prefer the more specific 404 error. That's what every framework I've ever seen does.

Also, RFC 2616 is out of date. Check out 7230 through 7239 for the most recent iteration.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.