Increasingly, developers and architects are disaggregating their architectures to create more scalable and agile applications. As this happens, everything is becoming a programmable endpoint. Ballerina is a new programming language designed around this problem. This deck introduces the challenges and background of why Ballerina has been created, as well as demonstrate the core features of the language.
10. import ballerina/http;
listener http:Listener httpListener = new(9090);
// RESTful service.
@http:ServiceConfig { basePath: "/ordermgt" }
service orderMgt on httpListener {
// Resource that handles the HTTP GET requests that are directed to a specific
@http:ResourceConfig {
methods: ["GET"],
path: "/order/{orderId}"
}
resource function findOrder(http:Caller caller, http:Request req, string
orderId) {
// Implementation
}
// Resource that handles the HTTP POST requests that are directed to the path
@http:ResourceConfig {
methods: ["POST"],
path: "/order"
}
resource function addOrder(http:Caller caller, http:Request req) {
...
12. import ballerina/http;
// Service endpoint
listener http:Listener travelAgencyEP = new(9090);
// Client endpoint to communicate with Airline reservation service
http:Client airlineReservationEP = new("http://localhost:9091/airline");
...
// Travel agency service to arrange a complete tour for a user
@http:ServiceConfig {basePath:"/travel"}
service travelAgencyService on travelAgencyEP {
...
// Send a post request to airline service with appropriate payload and get
response
http:Response inResAirline = check airlineReservationEP->post("/reserve",
untaint outReqPayloadAirline);
20. Basic types and other types
○ Other types
○ Unions
○ Optional
○ json
○ byte
○ anydata
○ any
21. Union types
○ Type defined by union of two or more other types
○ Remember, a type is name for a set of values
float | string v1 = "John";
float | string v2 = 457.68;
float | string
0.51
1.01
457.68
-11.0
“John”
“name”
“”
“bal”
// The return type of 'post' is a union of 'http:Response' and 'error'
http:Response | error response = orderEP -> post("/create", reqPayload)
22. XML
// Simple XML literal
xml x1 = xml`<name>Pol Katta</name>`;
// XML with namespaces
xmlns "http://wso2.com" as ns0;
xml x2 = xml `<name id="123" status="single">
<ns0:fname>Pol</ns0:fname>
<ns0:lname>Katta</ns0:lname>
</name>`;
// XML literal with interpolation
string lastName = "Katta";
xml x3 = xml`<lname>${lastName}</lname>`;
// Concat XML values
xml x4 = x1 + x2 + x3;
28. import ballerina/http;
import ballerinax/docker;
@docker:Config {
registry:"ballerina.guides.io",
name:"travel_agency_service",
tag:"v1.0"
}
@docker:Expose{}
listener http:Listener travelAgencyEP = new(9090);
// http:Client endpoint definitions to communicate with other services
@http:ServiceConfig {basePath:"/travel"}
service travelAgencyService on travelAgencyEP {
@kubernetes:Ingress {
hostname:"ballerina.guides.io",
name:"ballerina-guides-travel-agency-service",
path:"/"
}
@kubernetes:Service {
serviceType:"NodePort",
name:"ballerina-guides-travel-agency-service"
}
@kubernetes:Deployment {
image:"ballerina.guides.io/travel_agency_service:v1.0",
name:"ballerina-guides-travel-agency-service"
}
29. ● Ballerina natively understand Cloud Native platforms like Docker,
Kubernetes and Istio.
● Ballerina removes gap between developers and Ops.
● Ballerina support agile development to deployment and improve
productivity.
Takeaways
30. How to get involved
Learn more
Open source
Get support
http://ballerina.io
http://github.com/ballerina-platform/
Ballerina Dev Google Group
Ballerina Slack Channel
Stack Overflow #ballerina tag