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 parameterHTTP module provides first class support for specifying |
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
# 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"}