Swan Lake Beta2 is here.
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!
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!

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand