Assume we have a JSON API endpoint called /users with a first_name attribute on the resource object.
The JSON API spec says that GET /users?fields[user]=first_name should return a sparse array of user objects with only the first_name attribute in the objects.
What actually happens currently is all attributes are returned, the fields[users] parameter is ignored, because the code currently matches against fields[user] instead. Furthermore, there's no feedback to a developer to indicate that the requested fields[.*] parameter is actually invalid and the request is bad.
Expected behavior:
fields[users]=first_name should return HTTP 200 with a list of people with first_name as the only attribute in the payload
fields[user]=first_name should return HTTP 400 with a payload error indicating that the fields[user] is invalid
Assume we have a JSON API endpoint called
/userswith afirst_nameattribute on the resource object.The JSON API spec says that
GET /users?fields[user]=first_nameshould return a sparse array ofuserobjects with only thefirst_nameattribute in the objects.What actually happens currently is all attributes are returned, the
fields[users]parameter is ignored, because the code currently matches againstfields[user]instead. Furthermore, there's no feedback to a developer to indicate that the requestedfields[.*]parameter is actually invalid and the request is bad.Expected behavior:
fields[users]=first_nameshould returnHTTP 200with a list ofpeoplewithfirst_nameas the only attribute in the payloadfields[user]=first_nameshould returnHTTP 400with a payload error indicating that thefields[user]is invalid