Skip to content

Instantly share code, notes, and snippets.

@MaryamZi
Last active February 5, 2018 09:43
Show Gist options
  • Save MaryamZi/be0c4f8c723d96a72c611978d3a098ca to your computer and use it in GitHub Desktop.
Save MaryamZi/be0c4f8c723d96a72c611978d3a098ca to your computer and use it in GitHub Desktop.
Sample demonstrating a GitHub webhook with Ballerina
import ballerina.net.http;
@http:configuration {basePath:"/githubWebhook"}
service<http> githubWebhook {
@http:resourceConfig {
methods:["POST"],
path:"/listener"
}
resource webhookListener (http:Connection connection, http:InRequest request) {
println("HEADER: X-GitHub-Event --> " + request.getHeader("X-GitHub-Event").value);
println("HEADER: X-GitHub-Delivery --> " + request.getHeader("X-GitHub-Delivery").value);
if (request.getHeader("X-Hub-Signature") != null) {
println("HEADER: X-Hub-Signature --> " + request.getHeader("X-Hub-Signature").value);
}
json jsonMsg = request.getJsonPayload();
println(jsonMsg);
http:OutResponse res = {};
res.statusCode = 202;
_ = connection.respond(res);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment