PDVL

Ballerina Apr 2026

type Person record string name; int age; string email?; // optional field ; Person p = name: "Alice", age: 30 ; Arrays & Maps int[] numbers = [1, 2, 3]; map<string> colors = red: "#FF0000", green: "#00FF00" ; 5. Services & Listeners A service is a collection of remote methods (resources) attached to a listener (e.g., HTTP listener). HTTP Service Example import ballerina/http; service /api on new http:Listener(9090) resource function get greeting(string name) returns string return "Hello, " + name;

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:

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); ballerina

return a / b;

[container.image] repository = "myorg/myapi" name = "myapi" tag = "v1.0" Ballerina includes a built-in test framework. type Person record string name; int age; string email

Call:

brew install ballerina

type Employee record string name; int salary; ; Employee[] employees = [ name: "Alice", salary: 5000 , name: "Bob", salary: 6000 ];

import ballerina/test; @Test function testAddition() int result = 2 + 2; test:assertEquals(result, 4); http:Client client = check new ("https://jsonplaceholder