Last active
May 9, 2022 03:07
-
-
Save xlight05/d611c28f9486c9f7ee29d5a2d4a1e9a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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