import ballerina/http;

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

    // Resource functions are invoked with the HTTP caller and the
    // incoming request as arguments.
    resource function sayHello(http:Caller caller,
        http:Request req) returns error? {
        // Send a response back to the caller.
        check caller->respond("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 hello on new http:Listener(9090) {

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

    resource function sayHello(http:Caller caller,
        http:Request req) returns error? {

Resource functions are invoked with the HTTP caller and the incoming request as arguments.

        check caller->respond("Hello, World!");
    }
}

Send a response back to the caller.

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

Invoke the service using this “curl” command below.