This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "io/ioutil" | |
| "log" | |
| "net/http" | |
| ) | |
| func main() { |
This file contains hidden or 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
| # Build tool files | |
| .gradle/ | |
| .mvn/ | |
| /out | |
| /build | |
| node_modules/ | |
| # Compiled class file | |
| *.class |
This file contains hidden or 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/config; | |
| import ballerina/http; | |
| import ballerina/io; | |
| import ballerina/log; | |
| import wso2/github4; | |
| endpoint github4:Client githubClient { | |
| clientConfig: { | |
| auth: { | |
| scheme: http:OAUTH2, |
This file contains hidden or 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/log; | |
| http:Client clientEP = new("http://localhost:9095", config = { httpVersion: "2.0" }); | |
| public function main() { | |
| // Submit a `GET` request. | |
| http:Request serviceReq = new; | |
| http:HttpFuture httpFuture = checkpanic clientEP->submit("GET", "/hello/sayHello", serviceReq); |
This file contains hidden or 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; | |
| listener http:Listener helloWorldEP = new(9095, config = { httpVersion: "2.0" }); | |
| service hello on helloWorldEP { | |
| resource function sayHello(http:Caller caller, http:Request req) { | |
| // Send a Push Promises for 2 resources with 2 methods. | |
| http:PushPromise promise1 = new(path = "/resource1", method = "GET"); |
This file contains hidden or 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; | |
| listener http:Listener helloWorldEP = new(9095, { httpVersion: "2.0" }); | |
| service hello on helloWorldEP { | |
| resource function sayHello(http:Caller caller, http:Request req) { | |
| checkpanic caller->respond("Ballerina HTTP/2 Response !"); | |
| } | |
| } |
This file contains hidden or 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/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) { |
This file contains hidden or 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/io; | |
| import ballerina/http; | |
| import ballerina/config; | |
| import ballerina/runtime; | |
| function main(string... args) { | |
| testNoAuth(); | |
| testBasicAuth(); | |
| testOAuth2(); | |
| testJWTAuth(); |
This file contains hidden or 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
| endpoint http:Client jwtAuthClient { | |
| url: "https://www.example.org/api/v1", | |
| auth: { | |
| scheme: http:JWT_AUTH | |
| } | |
| }; | |
| public function testJWTAuth() { | |
| setJwtTokenToAuthContext(); | |
| string requestPath = "/employees"; |
This file contains hidden or 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
| endpoint http:Client oauthClient { | |
| url: "https://www.example.org/api/v1", | |
| auth: { | |
| scheme: http:OAUTH2, | |
| accessToken: "yf29.PlrfBb0gtDFXsbnE_LcDCG-Dz3djEp05zM9y-IPR8CsZz90XwOEyrhqeXPPYxubY9RHMIFzoV2", | |
| clientId: "50332352747-270vchcnbhbl4gfn1v91hl0fru.apps.example.org", | |
| clientSecret: "PrfEadE4s2SDG4hJ", | |
| refreshToken: "5/lk-u0Ywefgh52-v0_OLOkDhlsA9xIadf4qqD3TMQvc", | |
| refreshUrl: "https://www.example.com/oauth2/v3/token" | |
| } |