import ballerina/http;

service /company on new http:Listener(9090) {

    // The path param is defined as a part of the resource path along with the type and it is extracted from the
    // request URI.
    resource function get empId/[int id]() returns json {
        return {empId: id};
    }

    resource function get empName/[string first]/[string last]() returns json {
        return {firstName: first, lastName: last};
    }
}

Path Parameter

HTTP module provides first class support for specifying Path parameters in the resource path along with the type. The supported types are string, int, float, boolean, and decimal (e.g., path/[string foo]).

For more information on the underlying module, see the HTTP module.

import ballerina/http;
service /company on new http:Listener(9090) {
    resource function get empId/[int id]() returns json {
        return {empId: id};
    }

The path param is defined as a part of the resource path along with the type and it is extracted from the request URI.

    resource function get empName/[string first]/[string last]() returns json {
        return {firstName: first, lastName: last};
    }
}
bal run http_path_param.bal
[ballerina/http] started HTTP/WS listener 0.0.0.0:9090
# Run the cURL command below to invoke the service.
curl "http://localhost:9090/company/empId/23"
{"empId":23}
curl "http://localhost:9090/company/empName/Adele/Ferguson"
{"firstName":"Adele", "lastName":"Ferguson"}