Quantcast
Channel: Question and Answer » json
Viewing all articles
Browse latest Browse all 148

JSON API specification : When do I need to return a 404 not found?

$
0
0

I’m working on a REST api following the JSON api specification and I’m struggling with the “no data” responses (described here).

A server MUST respond with 404 Not Found when processing a request to
fetch a single resource that does not exist, except when the request
warrants a 200 OK response with null as the primary data (as described
above).

The “described above” refers to the previous section of the specification :

A server MUST respond to a successful request to fetch an individual
resource with a resource object or null provided as the response
document’s primary data.

null is only an appropriate response when the requested URL is one
that might correspond to a single resource, but doesn’t currently.

I don’t understand when I need to return a HTTP 404 Not Found and when I need with HTTP 200 OK with {"data":null}.

For example, if I have the following URL :

http://example.org/users/52

This URL is correct, but the User referenced by the ID 52 doesn’t exist.What is the correct response ? A 404 or a 200 data: null ?


Viewing all articles
Browse latest Browse all 148

Trending Articles