import ballerina/http;

// By default, Ballerina exposes an HTTP service via HTTP/1.1.
service / on new http:Listener(9090) {

    // The resource method is invoked by the GET request for the
    // `/greeting` path. The returned string value
    // eventually becomes the payload of the `http:Response`.
    resource function get greeting() returns string {
        return "Hello, World!";
    }
}

Hello World Service

In Ballerina, services represent collections of network-accessible entry points. Resources represent one such entry point. How a resource is exposed over a network protocol depends on the listener to which a service is attached.

import ballerina/http;
service / on new http:Listener(9090) {

By default, Ballerina exposes an HTTP service via HTTP/1.1.

    resource function get greeting() returns string {
        return "Hello, World!";
    }
}

The resource method is invoked by the GET request for the /greeting path. The returned string value eventually becomes the payload of the http:Response.

# To start the service, navigate to the directory that contains the
# `.bal` file, and execute the `bal run` command below.
bal run hello_world_service.bal
[ballerina/http] started HTTP/WS listener 0.0.0.0:9090
curl http://localhost:9090/greeting
Hello, World!

Invoke the service using the “cURL” command below.