Swan Lake Beta2 is here.
import ballerina/http;

// Base path of this service is `/demo`.
service /demo on new http:Listener(8080) {
    // You can combine base path and relative path to get the path of the resource, that is `/demo/greeting/hello`.
    resource function get greeting/hello(string name) returns string {
        return "Hello, " + name;
    }

}

Hierarchical Resources

Resource name is relative path, which can have multiple path segments. Base path is absolute path. A listener can have multiple services each with different base paths.

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

Base path of this service is /demo.

    resource function get greeting/hello(string name) returns string {
        return "Hello, " + name;
    }

You can combine base path and relative path to get the path of the resource, that is /demo/greeting/hello.

}
bal run hierarchical_resources.bal
[ballerina/http] started HTTP/WS listener 0.0.0.0:8080
# Run this cURL command to invoke the resource.
curl "localhost:8080/demo/greeting/hello?name=Ballerina"
Hello, Ballerina
import ballerina/http;

// Base path of this service is `/demo`.
service /demo on new http:Listener(8080) {
    // You can combine base path and relative path to get the path of the resource, that is `/demo/greeting/hello`.
    resource function get greeting/hello(string name) returns string {
        return "Hello, " + name;
    }

}

Hierarchical Resources

Resource name is relative path, which can have multiple path segments. Base path is absolute path. A listener can have multiple services each with different base paths.

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

Base path of this service is /demo.

    resource function get greeting/hello(string name) returns string {
        return "Hello, " + name;
    }

You can combine base path and relative path to get the path of the resource, that is /demo/greeting/hello.

}
bal run hierarchical_resources.bal
[ballerina/http] started HTTP/WS listener 0.0.0.0:8080
# Run this cURL command to invoke the resource.
curl "localhost:8080/demo/greeting/hello?name=Ballerina"
Hello, Ballerina

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