Admin: remove unused JS code (#12383)
[spree.git] / docs / api-reference / fetching-multiple-resources.mdx
blob479a858133dad08c1da382efccca84f3028e90f7
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:
3 ```curl
4 curl --request GET \
5      --url 'https://demo.spreecommerce.org/api/v2/storefront/products/classic-varsity-top?include=variants%252Cimages' \
6      --header 'Accept: application/vnd.api+json'
7 ```
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.
14 ## Nested resources
16 You can also nest resources, eg. fetching Product Variants with their Option Values:
18 ```curl
19 curl --request GET \
20      --url 'https://demo.spreecommerce.org/api/v2/storefront/products/classic-varsity-top?include=variants.option_values' \
21      --header 'Accept: application/vnd.api+json'
22 ```
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.