0

If I have the following REST API:

/resource/{id}

where the id's are hashes of specific information. If it is accessed with an id that is not "correct" e.g. 'abc' (/resource/abc),

Should this result in a 404 not found or should i result in something else?

2 Answers 2

3

Yes, it should be a 404 if you're attempting a queryless GET. You're specifying a resource path that cannot be found, and this is what a 404 signifies.

If you're trying to get with bad query params you might want a 400.

If you trying to query the resource with a method not supported, you might want 405.

Read http status codes and you should be able to decide what you really need.

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

4 Comments

This is what I thought. Just to clarify: Let's say that the id's were verified in the server (e.g. they need to have the following format <ENOCH-TIMESTAMP>-<HASHED-SOMETHING), would it still be a 404 when having an incorrect id or could it also be a 400 bad request?
@Aesthete: Exactly right. With one caveat - if the specified "id" is known to have existed but is no longer available then it would also be OK to return a 410 response.
When you identify resources like your example, resource/id, it either exists or it doesn't. If you have parameters to support your query and they are bad, perhaps you need a 400.
@pka: No, "bad syntax" doesn't refer to the URL itself in the case of 400 responses - it refers to the body of the HTTP request.
1

It depends on http method you use. 404 Not found for GET request will be definitely ok.

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.