If a client requests a resource that doesn't exist from my REST application, like
http://localhost:8080/app/foo/1
and no Foo resource exists for that id, should I return a 404 error code? or should I return 200 with a body of {"data": null }
?
Reading this thread from ember data makes me think I should return a 404.
But when I read this passage from the JSONAPI spec it makes me think I should return {"data " : null}
:
Primary data MUST be either:
- a single resource object, a single resource identifier object, or null, for requests that target single resources
- an array of resource objects, an array of resource identifier objects, or an empty array ([]), for requests that target resource collections
because this case seems to be targeting a single resource.
In the section Parsing Data it says:
A server MUST respond to a successful request to fetch an individual resource or resource collection with a 200 OK response.
What does "successful" mean? if the query doesn't find anything because there's not an entry there, the query ran and got an accurate result, is that success?
and below that in the same section is:
null is only an appropriate response when the requested URL is one that might correspond to a single resource, but doesn’t currently.
where I'm not clear on what that is supposed to mean.
So which is it and why?
(This isn't meant to be specifically about ember-data, I would like to clarify what I should do to be in compliance with the spec. I only mentioned ember-data because it seems like a working reference implementation for how jsonapi should work.)