Skip to content

Instantly share code, notes, and snippets.

@xlight05
Last active May 9, 2022 03:07
Show Gist options
  • Save xlight05/d611c28f9486c9f7ee29d5a2d4a1e9a6 to your computer and use it in GitHub Desktop.
Save xlight05/d611c28f9486c9f7ee29d5a2d4a1e9a6 to your computer and use it in GitHub Desktop.
import ballerina/http;
import ballerina/xmldata;
listener http:Listener securedEP = new(9090);
final http:Client nettyEP = check new("http://netty:8688");
service /transform on securedEP {
resource function post .(http:Request req) returns http:Response|http:BadRequest|error {
json payload = check req.getJsonPayload();
xml? xmlPayload = check xmldata:fromJson(payload);
if (xmlPayload is xml) {
http:Request clinetreq = new;
clinetreq.setXmlPayload(xmlPayload);
return <http:Response> check nettyEP->post("/service/EchoService", clinetreq);
} else {
return <http:BadRequest> {
body: "error converting json to xml"
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment