nemenems
nemenems

Reputation: 1092

What HTTP code should my API use if the resource does not exist

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.

Upvotes: 1

Views: 88

Answers (1)

cosbor11
cosbor11

Reputation: 16024

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.

Upvotes: 2

Related Questions