Skip to content

Instantly share code, notes, and snippets.

@ldclakmal
Last active January 17, 2020 09:54
Show Gist options
  • Save ldclakmal/4536607552d271b7d4fe53828e73ac77 to your computer and use it in GitHub Desktop.
Save ldclakmal/4536607552d271b7d4fe53828e73ac77 to your computer and use it in GitHub Desktop.
Ballerina HTTP/2 client
import ballerina/http;
import ballerina/log;
http:Client clientEP = new("http://localhost:9095", config = { httpVersion: "2.0" });
public function main() {
var responseVar = clientEP->post("/hello/sayHello", "Hello Ballerina!");
if (responseVar is http:Response) {
var payload = responseVar.getTextPayload();
if (payload is string) {
log:printInfo(payload);
} else {
log:printError("Error while reading payload.", payload);
}
} else {
log:printError("Error while sending POST request.", responseVar);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment