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

Respond with 404 status for single resources that do not exist #272

Closed
buschtoens opened this issue Dec 22, 2016 · 1 comment
Closed

Respond with 404 status for single resources that do not exist #272

buschtoens opened this issue Dec 22, 2016 · 1 comment

Comments

@buschtoens
Copy link

In accordance with the JSONAPI spec (Fetching Resources > 404 Not Found) Katharsis must respond with a 404 Not Found status for requests to single resources that do not exist. It currently responds with 200 Ok.

The response body is also incorrect:

{
  "data": null,
  "included": []
}

Although the empty included array is unnecessary, it is not illegal per se, as data is provided. However, "data": null is illegal in this context and so included is also.

Instead Katharsis should either respond with an empty response body (discouraged) or a proper errors field. There's an issue over at json-api/json-api#1122 (comment) elaborating on that.

The perfect response would look similar to this:

HTTP/1.1 404 Not Found
Content-Type: application/vnd.api+json

{
  "links": {
    "self": "http://example.com/authors/unknown-author"
  },
  "errors": [
    {
      "status": "404",
      "title": "Not Found",
      "detail": "Could not find a resource of type 'author' with id 'unknown-author'."
    }
  ]
}

The only exception to this rule is when requesting a single resource via a relationship link that is not yet set:

HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "links": {
    "self": "http://example.com/articles/1/author"
  },
  "data": null
}
@chb0github
Copy link
Contributor

chb0github commented Dec 22, 2016 via email

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

No branches or pull requests

3 participants