string? maybeName = "Jane"; maybeName = (); // nil function divide(int a, int b) returns int|error if b == 0 return error("Division by zero");
curl http://localhost:9090/api/greeting/John Call external services using built-in clients.
worker w2 returns int return 20;
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.
public function main() future<int> f1 = start task1(); future<string> f2 = start task2(); ballerina
[container.image] repository = "myorg/myapi" name = "myapi" tag = "v1.0" Ballerina includes a built-in test framework.
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: string
bal run hello.bal Variables & Types int age = 30; string name = "Alice"; boolean active = true; float pi = 3.14; decimal precise = 10.0d; byte[] data = [1, 2, 3]; json j = "name": "Bob" ; xml x = `<person>John</person>`; Optional Types & Error Handling Ballerina uses optional types ( T? ) and error union types ( T|error ).