forked from membrane/api-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path50-Loop-get-Details.yaml
More file actions
48 lines (47 loc) · 1.45 KB
/
50-Loop-get-Details.yaml
File metadata and controls
48 lines (47 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# yaml-language-server: $schema=https://www.membrane-api.io/v7.1.2.json
#
#
# Tutorial: For Loop
#
# Fetches a list of products from:
# https://api.predic8.de/shop/v2/products
# The list contains ids and names, but no prices. The gateway then loops over
# the list and fetches the price for each product via:
# https://api.predic8.de/shop/v2/products/{id}
#
# Try:
# curl localhost:2000
api:
port: 2000
flow:
- request:
# Fetch a list of products without price information
- call:
url: https://api.predic8.de/shop/v2/products?limit=7
# Iterate over the products array in the response
- for:
in: $.products
language: jsonpath
flow:
- log:
message: 'Fetching price for: ${it["name"]}'
- call:
url: https://api.predic8.de${it['self_link']}
# Collect name and price in a result list
- groovy:
src: |
property.res = property.res ?: []
property.res.add(
[ "name": it['name'],
"price": fn.jsonPath('$.price')
])
# Render the aggregated result as JSON
- template:
contentType: application/json
pretty: true
src: |
{
"products": <%= property.res %>
}
- return:
status: 200