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

Differences with JSON:API specification #179

Open
freiden opened this issue Apr 20, 2016 · 2 comments
Open

Differences with JSON:API specification #179

freiden opened this issue Apr 20, 2016 · 2 comments

Comments

@freiden
Copy link

freiden commented Apr 20, 2016

Hi,
Nice work on your gem the files and classes structures really ease the read of the code.
I was discovering the specification of JSON:API while testing your gem and I've seen some behaviors that doesn't seem to respect it.

  • Can I ask you why all the returned results are ResultSet and not some times resources when querying only one specific resource?
  • Can you give me some details on the usefulness of the last_result_set attribute?

Thanks by advance for your answer.

@chingor13
Copy link
Collaborator

I always have the request return a JsonApiClient::ResultSet so that I can be confident in the return type (and that I have access to the meta data of the response as well). The fact that it always returns an array-like thing is a remnant from the initial specifications where every endpoint was supposed to return an array (so you can always iterate over all the results like you can in jQuery).

The switch back to singular/multiple resource objects returned was a pretty late design change in the spec and I had already implemented and was using a pre-release version (I still maintain a 0.x branch). I decided that the consumer of the client shouldn't have to interrogate to see if you could call each or just use the resulting object and just always know that it's an array-like thing. As a consumer, if you know you get back 0 or 1 things, then you can call .first on the result set.

The last_result_set attribute is there if you are doing actions on a resource instance (like update) and you want access to the metadata. .save on resource instance behaves similarly to ActiveRecord (returns true/false) and sets errors if it failed. If you don't have access to the last_result_set, then we've lost metadata from that request.

@freiden
Copy link
Author

freiden commented Apr 28, 2016

Ok thanks for the answer.
Do you plan to change the behavior on the ResulSet to match the current specification?

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