Swan Lake Beta3 is here.
import ballerina/http;

service /demo on new http:Listener(8080) {
    // Here is how you can make path segments as parameters.
    resource function get greeting/hello/[string name]() returns string {

        return "Hello, " + name;
    }
}

Resource Path Parameters

Path segments can be treated as parameters in Ballerina.

import ballerina/http;
service /demo on new http:Listener(8080) {
    resource function get greeting/hello/[string name]() returns string {

Here is how you can make path segments as parameters.

        return "Hello, " + name;
    }
}
bal run resource_path_parameters.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/Ballerina" 
Hello, Ballerina
import ballerina/http;

service /demo on new http:Listener(8080) {
    // Here is how you can make path segments as parameters.
    resource function get greeting/hello/[string name]() returns string {

        return "Hello, " + name;
    }
}

Resource Path Parameters

Path segments can be treated as parameters in Ballerina.

import ballerina/http;
service /demo on new http:Listener(8080) {
    resource function get greeting/hello/[string name]() returns string {

Here is how you can make path segments as parameters.

        return "Hello, " + name;
    }
}
bal run resource_path_parameters.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/Ballerina" 
Hello, Ballerina
Subscribe to the newsletter

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