Using Zoom In Client Applications
Cortex uses hypermedia links to associate related resources together. Client applications need to make multiple requests to retrieve information from a resource’s links. Using zoom
, you can retrieve all these links with a single request. When a request uses zoom
, Cortex retrieves all the requested links and generates a single response containing the linked data. All links that can be retrieved can also be "zoomed".
zoom
Example Using In this example, zoom
retrieved the cart resource and its corresponding lineitems and total resources. Once the client application receives the response, JSONPath can extract the data you’re interested in.
{
"self": {
"type": "elasticpath.carts.cart",
"uri": "/carts/mobee/guz=?zoom=lineitems,total",
"href": "http://api.elasticpath.net/cortex/carts/mobee/guz=?zoom=lineitems,total"
},
"total-quantity": 3,
"links": [
{
"rel": "lineitems",
"rev": "cart",
"type": "elasticpath.collections.links",
"uri": "/carts/mobee/guz=/lineitems",
"href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems"
},
{
"rel": "order",
"rev": "cart",
"type": "elasticpath.orders.order",
"uri": "/orders/mobee/mu3=",
"href": "http://api.elasticpath.net/cortex/orders/mobee/mu3="
},
{
"rel": "total",
"rev": "cart",
"type": "elasticpath.totals.total",
"uri": "/totals/carts/mobee/guz=",
"href": "http://api.elasticpath.net/cortex/totals/carts/mobee/guz="
}
],
"_lineitems": [
{
"self": {
"type": "elasticpath.collections.links",
"uri": "/carts/mobee/guz=/lineitems",
"href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems"
},
"links": [
{
"rel": "element",
"rev": "list",
"type": "elasticpath.carts.line-item",
"uri": "/carts/mobee/guz=/lineitems/hfq=",
"href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems/hfq="
},
{
"rel": "element",
"rev": "list",
"type": "elasticpath.carts.line-item",
"uri": "/carts/mobee/guz=/lineitems/gbq=",
"href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems/gbq="
},
{
"rel": "cart",
"rev": "lineitems",
"type": "elasticpath.carts.cart",
"uri": "/carts/mobee/guz=",
"href": "http://api.elasticpath.net/cortex/carts/mobee/guz="
}
]
}
],
"_total": [
{
"self": {
"type": "elasticpath.totals.total",
"uri": "/totals/carts/mobee/guz=",
"href": "http://api.elasticpath.net/cortex/totals/carts/mobee/guz="
},
"cost": [
{
"amount": 211,
"currency": "CAD",
"display": "$211.00"
}
],
"links": [
{
"rel": "cart",
"rev": "total",
"type": "elasticpath.carts.cart",
"uri": "/carts/mobee/guz=",
"href": "http://api.elasticpath.net/cortex/carts/mobee/guz="
}
]
}
]
}
total-quantity
child property
Extract JSONPath: $total-quantity
Result:
[
3
]
quantity
value nested in other properties
Extract every JSONPath: $..quantity
Result:
[
2,
1
]
cost
array
Extract first element of total JSONPath: $_total..cost[0]
Result:
[
{
"amount": 211,
"currency": "CAD",
"display": "$211.00"
}
]