forked from membrane/api-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapis-preview.yaml
More file actions
87 lines (76 loc) · 1.96 KB
/
apis-preview.yaml
File metadata and controls
87 lines (76 loc) · 1.96 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# yaml-language-server: $schema=https://www.membrane-api.io/v7.1.2.json
components:
myBean:
bean:
class: java.lang.String
constructorArgs:
- constructorArg:
value: Greetings from Spring
---
api:
port: 2000
flow:
- request:
- groovy:
src: |
// Return Json as Map
[id:7,city:'Berlin']
# Return response to Client
- return:
contentType: application/json
---
api:
port: 2010
flow:
- request:
- groovy:
src: |
// JSON to JSON transformation
// The json-Variable contains the request or response body as JSON object.
import java.text.*
def dfIn = new SimpleDateFormat("d MMM yyyy",Locale.US)
def dfOut = new SimpleDateFormat("yyyy-MM-dd")
[
id: json.id,
date: dfOut.format(dfIn.parse(json.date)),
client: json.customer,
total: json.items.collect { it.price * it.quantity }.sum(),
positions: json.items.collect {
[
pieces: it.quantity,
price: it.price,
article: it.description
]
}
]
- return: {}
---
api:
port: 2020
flow:
- request:
- groovy:
src: |
println "Request headers:"
header.entrySet().each {
println it
}
# Execute groovy-Interceptor in response flow
- response:
- groovy:
src: |
header.add("X-Groovy", "42") // Set Header
CONTINUE
target:
host: localhost
port: 2030
---
api:
port: 2030
flow:
- request:
- groovy:
src: |
// Create response and set the body to the value of the component
Response.ok().body(router.getRegistry().getBean('myBean')).build()
- return: {}