-
Notifications
You must be signed in to change notification settings - Fork 0
/
pasthrough.bal
44 lines (37 loc) · 1.25 KB
/
pasthrough.bal
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
import ballerina/http;
import ballerina/log;
http:Client clientEP = new ("http://localhost:9092/hello");
service passthrough on new http:Listener(9090) {
@http:ResourceConfig {
path: "/"
}
resource function passthrough(http:Caller caller, http:Request req) {
var clientResponse = clientEP->forward("/", req);
if (clientResponse is http:Response) {
var result = caller->respond(clientResponse);
if (result is error) {
log:printError("Error sending response", result);
}
} else {
http:Response res = new;
res.statusCode = 500;
res.setPayload(<string>clientResponse.detail()?.message);
var result = caller->respond(res);
if (result is error) {
log:printError("Error sending response", result);
}
}
}
}
service hello on new http:Listener(9092) {
@http:ResourceConfig {
methods: ["POST", "PUT", "GET"],
path: "/"
}
resource function helloResource(http:Caller caller, http:Request req) {
var result = caller->respond("Hello World!");
if (result is error) {
log:printError("Error sending response", result);
}
}
}