1

In a REST API which HTTP code should I use if the client calls a non existing resource?

Ex:

GET /messsssssssages/42

I already map every other http codes (resource not found = 404 etc...) but I can't decide how to map this one.

2
  • why not stick with 404? Commented Dec 14, 2016 at 10:24
  • I hesitate between 404 and 400. For my comprehension, in REST API 404 is for a resource not found (the id is not present in DB) here, this is clearly a routing error. Should it be a 404? I don't know... Commented Dec 14, 2016 at 10:28

1 Answer 1

2

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.

You can map 404 Not found to a valid resource that does not have an instance with that ID and can also map 404 to there is no resource by that name.

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.