1 Spree APIs allow you to fetch multiple associated resources in one API call, both for singular resources and collections, eg. we can fetch a Product with all of its variants and images:
5 --url 'https://demo.spreecommerce.org/api/v2/storefront/products/classic-varsity-top?include=variants%252Cimages' \
6 --header 'Accept: application/vnd.api+json'
9 This will return a JSON response with `data[relationships]` node (links to what resources connects to which) and `included` node (images and variants JSON responses).
11 This way you can easily control what resources you want to include in the response and
12 avoid making multiple API calls.
16 You can also nest resources, eg. fetching Product Variants with their Option Values:
20 --url 'https://demo.spreecommerce.org/api/v2/storefront/products/classic-varsity-top?include=variants.option_values' \
21 --header 'Accept: application/vnd.api+json'
24 ## Open source libraries to transform JSONApi to a flat JSON response
26 As you probably noticed the JSON response can sometimes be quite big and hard to follow. To ease working with included resources we recommend checking out [one of the open-source libraries](https://jsonapi.org/implementations/) that can help deserialize responses.