her icon indicating copy to clipboard operation
her copied to clipboard

Support for JSON API's Compound Documents

Open alexchumak opened this issue 10 years ago • 5 comments

Using combination of relationships and included related resources it is possible to avoid making many unnecessary API calls.

http://jsonapi.org/format/#document-compound-documents

"data": [
  {
    "id": "59d23d10-1aa3-11e5-8c51-f1d09152a8c3",
    "type": "activities",
    "attributes": {
      "ip": "x.x.211.243",
      "bot": false
    },
    "relationships": {
      "user_agent": {
        "data": {
          "type": "user_agents",
          "id": "1"
        }
      }
    }
  }
],
"included": [
  { "type": "user_agents", "id": "1", "attributes": { "os": "windows", "browser": "chrome" } }
]

After parsing that response activity.user_agent should be present, without any additional API calls.

Is there any appetite for adding this seemingly priceless functionality?

alexchumak avatar Jul 07 '15 23:07 alexchumak

@alexchumak this is actively being worked on (by me), so i hope so :-)

https://github.com/hubert/her/tree/feature/jsonapi-compound-documents

it's not quite ready to be merged in but i'll PR soon. there is one bit of work i needed to do with regards to has_one associations were being handled in order to get this to work, so that will need to get merged and then this will come soon after.

comments welcome and appreciated.

hubert avatar Jul 07 '15 23:07 hubert

That's great news @hubert! I even forked it myself and was about start mucking around with it, but glad i asked first!

Looking forward to taking advantage of this functionality. Do you have any sense as to when this might get merged into master?

alexchumak avatar Jul 08 '15 14:07 alexchumak

Hello @hubert. We are keen to help with this if we can. I've merged your earlier work and I see that your has_one PR has been pulled in. The basic assembly of compound documents seems to work very well and I like the way it simply prevents a future api call. Thank you for that. Is there other work in this area that we could help to finish?

We are finding the jsonapi parsing quite fragile, especially around associations. I don't think that's related to the compound document parsing - more to do with #334 - but it becomes more important when bundles of stuff are being passed around. Happy to come up with something there too.

will-r avatar Aug 04 '15 14:08 will-r

@will-r @alexchumak i'd encourage you to share your thoughts on PR #360

i have some qualms with it, but now that 0.8.0 has gone out, i'd be more inclined to merge it in if there are active users who would benefit.

@will-r do you have a example of the jsonapi parsing be fragile? i'd be keen to take a look.

hubert avatar Sep 07 '15 07:09 hubert

Hello,

it would be great if her could parse the associations sent on "relationships". Here is an example json for a call with a has_one relationship: https://gist.github.com/danielneis/255d4c931ca8191f5b8d0b2bc2a1c5ce

danielneis avatar Mar 09 '18 22:03 danielneis