xiaohutai / jsonapi

[Bolt Extension] JSON API for Bolt CMS
https://market.bolt.cm/view/bolt/jsonapi
MIT License
55 stars 18 forks source link

No matches returns a 400 - Bad request error #70

Closed jimcue closed 6 years ago

jimcue commented 7 years ago

A well-formed request that returns no results will get a 400 HTTP code (Bad request) error response.

With no item with id>100 the request http://example.com/json/articles?filter[id]=>100 gets:

{
    "errors": {
        "details": "Bad request: There were no results based upon your criteria!",
        "status": 400,
        "title": "Bad Request"
    }
}

Would it not make sense to get a 200 HTTP response with an empty list (or null for specific-item requests) as mentioned in the JSON API specs?

HTTP/1.1 200 OK
Content-Type: application/vnd.api+json
{
  "links": {
    "self": "http://example.com/articles"
  },
  "data": []
}
luminarious commented 6 years ago

204 No Content would be perfect.

rwd commented 6 years ago

As mentioned by @jimcue the JSON API spec states that the response code in this scenario MUST be 200 OK: http://jsonapi.org/format/#fetching-resources-responses

xiaohutai commented 6 years ago

Fixed via #80. Will be available in a new release later today (or tomorrow).

xiaohutai commented 6 years ago

Should be fixed in v3.2.0