import ballerina/http;

service / on new http:Listener(9090) {

    // This function responds with `string` value `Hello, World!` to HTTP GET requests.
    resource function get greeting() returns string {
        return "Hello, World!";
    }

}

Hello World Service

Let’s write a simple HTTP service in Ballerina. This example demonstrates the network primitives in the language that make it simpler to develop services.

import ballerina/http;
service / on new http:Listener(9090) {
    resource function get greeting() returns string {
        return "Hello, World!";
    }

This function responds with string value Hello, World! to HTTP GET requests.

}
bal run hello_world_service.bal
[ballerina/http] started HTTP/WS listener 0.0.0.0:9090
# Invoke the service using the "cURL" command below.
curl http://localhost:9090/greeting
Hello, World!