3 ms·
Does anyone knows if there is a REST variant that allows to send/get associated resources nested on a single call? Taking the customers+charges example on the
by otto_ortega 10y ago
Does anyone knows if there is a REST variant that allows to send/get associated resources nested on a single call?
Taking the customers+charges example on the article, something like:
POST /api/customers/null/charges
{
name: 'John Cash',
dob: '1990-01-01',
charges:[
{type:1, amount: 12.5},
{type:1, amount: 22.8}
]
}
I think the option to bundle things on a single call is wonderful, but GraphSQL seems much more complicated to implement than REST.
- throwaway2016a 10y ago> Does anyone knows if there is a REST variant that allows to send/get associated resources nested on a single call? Json API has standards for how to do related records. http://jsonapi.org/format/#fetching-includes http://jsonapi.org/format/#fetching-includes > I think the option to bundle things on a single call is wonderful, but GraphSQL seems much more complicated to implement than REST. Not necessarily. I find GraphQL easier to write and consume but harder to handle errors and pagination. Plus caching is impossible in GraphQL without client-side special code. But I use node.js which has avery mature GraphQL library. If there isn't a library for your language it would be very difficult. If done properly there are actually a lot of rules to doing REST. For example, that JSON you put is not REST because it doesn't have Hypermedia. Of course, REST has the benefit of requiring no external libraries except HTTP. And no one says you have to follow all the constraints of REST (though I recommend it).
- otto_ortega 10y agoAwesome, seems like the "JSON API" specification is the REST-ish API variant I was looking for. It has support for "related resources" and even "sparse fieldsets" (http://jsonapi.org/format/#fetching-sparse-fieldsets http://jsonapi.org/format/#fetching-sparse-fieldsets) which covers the main advantages I can see on GraphQL in reducing number of request and the size of the responses.