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
$ brew install ballerina | |
$ git clone https://github.com/choreodev/hello-svc | |
$ cd hello-svc | |
$ ballerina run hello-svc |
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/log; | |
import ballerina/stringutils; | |
// Service endpoint | |
listener http:Listener carEP = new(8090); | |
// Available car types | |
final string AC = "Air Conditioned"; | |
final string NORMAL = "Normal"; |
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/log; | |
import ballerina/stringutils; | |
import ballerina/observe; | |
// Service endpoint | |
listener http:Listener travelAgencyEP = new(8090); | |
// Client endpoint to communicate with Airline reservation service | |
http:Client airlineReservationEP = new("https://airline-booking-svc-nuwan.preprod.choreo.dev/airline"); |
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/io; | |
import ballerina/http; | |
//import miyurud/twilio; | |
//import ballerina/config; | |
import ballerina/observe; | |
#Twilio config | |
//twilio:TwilioConfiguration twilioConfig = { | |
// accountSId: "ACc055c08964b76ef55b0a755a3edcd6f3", | |
// authToken: "e5f33508721405842550c906c26febb2" |
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/log; | |
import ballerina/stringutils; | |
import ballerina/observe; | |
// Service endpoint | |
listener http:Listener travelAgencyEP = new(8090); | |
// Client endpoint to communicate with Airline reservation service | |
http:Client airlineReservationEP = new("https://airline-booking-svc-nuwan.preprod.choreo.dev/airline"); |
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
ballerina/http] stopped HTTP/WS listener 0.0.0.0:9190 | |
[pass] testFunction | |
1 passing | |
0 failing | |
0 skipped | |
Generating executables | |
target/bin/hello-service.jar |
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
service hello on new http:Listener(9090) { | |
resource function sayHello(http:Caller caller, http:Request req) { | |
var result = caller->respond("Hello, World!"); | |
if (result is error) { | |
log:printError("Error sending response", result); | |
} | |
} | |
} |
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
function bookAirline(http:Caller caller, map<json> outReqPayload, json | error airlinePreference, http:Response outResponse) returns error? { | |
// Reserve airline ticket for the user by calling Airline reservation service | |
// construct the payload | |
map<json> outReqPayloadAirline = outReqPayload.clone(); | |
outReqPayloadAirline["Preference"] = <json>airlinePreference; | |
// Send a post request to airlineReservationService with appropriate payload and get response | |
http:Response inResAirline = check airlineReservationEP->post("/reserve", <@untainted>outReqPayloadAirline); | |
// Get the reservation status |
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
[2019-05-10 00:31:24,739] TRACE {http.tracelog.downstream} - [id: 0x58654aba] REGISTERED | |
[2019-05-10 00:31:24,740] TRACE {http.tracelog.downstream} - [id: 0x58654aba, correlatedSource: n/a, host:/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:56173] ACTIVE | |
[2019-05-10 00:31:24,778] TRACE {http.tracelog.downstream} - [id: 0x58654aba, correlatedSource: n/a, host:/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:56173] INBOUND: DefaultHttpRequest(decodeResult: success, version: HTTP/1.1) | |
GET /v1/employees HTTP/1.1 | |
Host: localhost:9090 | |
User-Agent: curl/7.54.0 | |
Accept: */* | |
[2019-05-10 00:31:24,804] TRACE {http.tracelog.downstream} - [id: 0x58654aba, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:localhost/0:0:0:0:0:0:0:1:56173] INBOUND: EmptyLastHttpContent, 0B | |
[2019-05-10 00:31:24,807] TRACE {http.tracelog.downstream} - [id: 0x58654aba, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:localhost/0:0:0:0:0:0:0:1:56173] READ COMPLETE |
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
endpoint http:APIListener listener { | |
port:9090, | |
authProviders:[basicAuthProvider] | |
}; | |
// Add the authConfig in the ServiceConfig annotation to protect the service using Auth | |
@http:ServiceConfig { | |
basePath:"/e-shop", | |
authConfig:{ | |
authProviders:["basic1"], |
NewerOlder