forked from membrane/api-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapis.yaml
More file actions
61 lines (54 loc) · 1.6 KB
/
apis.yaml
File metadata and controls
61 lines (54 loc) · 1.6 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
49
50
51
52
53
54
55
56
57
58
59
60
61
# yaml-language-server: $schema=https://www.membrane-api.io/v7.1.2.json
api:
port: 2000
flow:
- request:
- javascript:
src: |
console.log("Query parameters: " + params);
// Return Json as Map
({ id: params.get('id')?.[0], city: params.get('city')?.[0] })
- return:
contentType: application/json
---
api:
port: 2010
flow:
- request:
- javascript:
src: |
// JSON to JSON transformation
function convertDate(d) {
return d.getFullYear() + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" + ("0"+d.getDate()).slice(-2);
}
({
id: json.id,
date: convertDate(new Date(json.date)),
client: json.customer,
total: json.items.map(i => i.quantity * i.price).reduce((a,b) => a+b),
positions: json.items.map(i => ({
pieces: i.quantity,
price: i.price,
article: i.description
}))
})
- return:
status: 200
---
api:
port: 2020
flow:
- request:
- javascript:
src: |
console.log("Request headers:")
for (var entry of header.entrySet()) {
console.log(entry.getKey() + ": " + entry.getValue());
}
- response:
- javascript:
src: |
header.add("X-Javascript", "42") // Set Header
CONTINUE
- return:
status: 200