Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP code 200 when resource not found #184

Open
AdrianVandierAst opened this issue Dec 27, 2019 · 1 comment
Open

HTTP code 200 when resource not found #184

AdrianVandierAst opened this issue Dec 27, 2019 · 1 comment

Comments

@AdrianVandierAst
Copy link

When a single resource is not found, the api responds a 200 OK response with {"data": null}.
There is even a test that checks that: test_get_detail_object_not_found.

But the json:api is explicit about that:

404 Not Found
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 200 OK response is only when the resource is a to-one relationship.

The 200 OK response for simple resource detail queries is intended for a reason i don't understand ?
If not, I will create a pull request.

@multimeric
Copy link
Contributor

So the spec also says:

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

Note: Consider, for example, a request to fetch a to-one related resource link. This request would
respond with null when the relationship is empty (such that the link is corresponding to no resources)
but with the single related resource’s resource object otherwise

I assume this is where what the current implementation is based on. GET /persons/3 is "a URL that might correspond to a single resource, but doesn’t currently" and also "a single resource that does not exist", so I'm not sure which is correct. Presumably it's the former, since it's not the same situation as a relationship for an existing object.

If it ends up that this implementation is wrong, feel free to also put in your PR to https://github.com/TMiguelT/flapison, since I can guarantee that I'll review and merge it, whereas I can't say the same for this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants