Ballerina (programming language)
Ballerina is a general-purpose programming language designed by WSO2 for cloud computing application software.[src] It is free and open-source software released under Apache License 2.[src] The project began in 2015 by architects from WSO2 as a code-based alternative to the configuration-based integration tools such as enterprise application integration (EAI), enterprise service bus (ESB), and workflow products.[src] It has various constructs for cloud-native development including support for various data formats and protocols, reliability, distributed transactions, application programming interfaces (APIs), and event streams.[src]
Ballerina is a general-purpose programming language designed by WSO2 for cloud computing application software.[src] It is free and open-source software released under Apache License 2.[src] The project began in 2015 by architects from WSO2 as a code-based alternative to the configuration-based integration tools such as enterprise application integration (EAI), enterprise service bus (ESB), and workflow products.[src] It has various constructs for cloud-native development including support for various data formats and protocols, reliability, distributed transactions, application programming interfaces (APIs), and event streams.[src] import ballerina/io; public function main() { io:println("Hello World!"); } To execute the above program, place the source code in a .bal file and provide the path of the file to the bal run command.[src] $ ballerina run hello_world.bal Hello World![src] The service version of the Hello World program: import ballerina/http; service /greet on new http:Listener(9090) { resource function get .[src] () returns string { return "Hello World!"; } } Services are executed in the same manner, except they don't terminate like regular programs do.[src] Once the service is up and running, one can use an HTTP client to invoke the service.[src] For example, the above service can be invoked using the following cURL command: $ curl http://localhost:9090/greet Hello World![src] import ballerina/http; service on new http:Listener(9090) { resource function post factorial(@http:Payload string payload) returns http:Ok|http:BadRequest { int|error num = int:fromString(payload); if num is error { return {body: "Invalid integer: " + payload}; } if num {body: "Integer should be >= 0"}; } int result = 1; foreach int i in 2 ...[src] num { result *= i; } return {body: result}; } } $ curl http://localhost:9090/factorial -d 5 120 import ballerina/graphql; service /stocks on new graphql:Listener(4000) { resource function get quote() returns StockQuote { return { ticker: "EXPO", price: 287.5, open: 285, prevClose: 285.5, low: 276.25, high: 297 }; } } type StockQuote record ; $ curl -H "Content-type: application/json" -d '{"query": "{ quote { ticker, price } }" }' 'http://localhost:4000/stocks' {"data":{"quote":{"ticker":"EXPO", "price":287.5}}} import ballerina/io; public function main() returns error { // Syntax for `json` object values is very similar to the syntax of JSON json person = {name: "John Doe", age: 25}; // Serialized `json` values conforms to the JSON specification io:println(person); // The fields of the `json` value can be accessed as follows string name = check person.name; int age = check person.age; } [package] distribution = "2201.0.0" [build-options] cloud="k8s" Cloud.toml file: [container.image] repository="bal_user" name="greet" tag="v0.1.0" import ballerina/http; import ballerina/lang.'int; import ballerina/io; // Workers interact with each other by sending and receiving messages.[src] // Ballerina validates every worker interaction (send and receive) // to avoid deadlocks.[src] public function main() { @strand {thread: "any"} worker w1 { int w1val = checkpanic calculate("2*3"); // Sends a message asynchronously to the worker `w2`.[src] w1val -> w2; // Receives a message from the worker `w2`.[src] int w2val = > w3; w2val -> w3; // Flushes all messages sent asynchronously to the worker `w3`.[src] The worker // will halt at this point until all messages are sent or until the worker `w3` // fails.[src] checkpanic flush w3; } // A worker can have an explicit return type, or else, if a return type is not mentioned, // it is equivalent to returning ().[src] @strand {thread: "any"} worker w2 { int w2val = checkpanic calculate("17*5"); // Receives a message from the worker `w1`.[src] int w1val = w1; } worker w3 { int|error w1val = get(string `/v4/?expr=${expr}`); return check 'int:fromString(response); } ==References==[src]
24 sentences · 24 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Ballerina (programming language)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/ballerina-programming-language. Accessed 06 December 2026.
Chicago
"Ballerina (programming language)." encyclopegia.org. Accessed December 6, 2026. https://encyclopegia.org/wiki/ballerina-programming-language.
APA
encyclopegia.org. (2026). Ballerina (programming language). Retrieved December 6, 2026, from https://encyclopegia.org/wiki/ballerina-programming-language
Accessed December 6, 2026 · CC BY-SA 4.0 · citation page · JSON