Ballerina uses strands – lightweight threads managed by the runtime. Use start , wait , and isolated functions.
bal build --cloud=docker bal build --cloud=k8s This creates a Dockerfile , docker-image.yaml , or Kubernetes YAML.
curl -fsSL https://dist.ballerina.io/downloads/install.sh | bash Use the MSI installer.
bal test myproject/ ├── Ballerina.toml # module metadata, dependencies ├── main.bal # entry point ├── modules/ │ └── auth/ # submodule │ ├── Module.md │ └── auth.bal ├── tests/ # test files │ └── main_test.bal └── target/ # build output Create a new project: ballerina
public function main() future<int> f1 = start task1(); future<string> f2 = start task2();
string? maybeName = "Jane"; maybeName = (); // nil function divide(int a, int b) returns int|error if b == 0 return error("Division by zero");
[container.image] repository = "myorg/myapi" name = "myapi" tag = "v1.0" Ballerina includes a built-in test framework. Ballerina uses strands – lightweight threads managed by
return a / b;
function task1() returns int return 42;
Here’s a comprehensive guide to , a modern, open-source programming language designed for cloud-native application integration and microservices development. 1. What is Ballerina? Ballerina is a graph-oriented, compiled language that treats distributed system integration as a first-class concern. It provides built-in support for network interactions, data transformations, and service resilience, making it ideal for APIs, integrations, and microservices. curl -fsSL https://dist
bal --version A Ballerina program is organized into modules (like packages). Each .bal file contains imports, functions, services, and listeners. Hello World import ballerina/io; public function main() io:println("Hello, World!");
int res1 = wait f1; string res2 = wait f2;
curl http://localhost:9090/api/greeting/John Call external services using built-in clients.
import ballerina/http; import ballerina/io; public function main() returns error? http:Client client = check new ("https://jsonplaceholder.typicode.com"); json response = check client->get("/posts/1"); io:println(response);