Last active
February 5, 2018 09:43
-
-
Save MaryamZi/be0c4f8c723d96a72c611978d3a098ca to your computer and use it in GitHub Desktop.
Sample demonstrating a GitHub webhook with Ballerina
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.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