Swan Lake Beta2 is here.
import ballerina/http;

// Service declaration specifies base path for the resource names. The base path is `/` in this example.
service / on new http:Listener(8080) {
    // Resource method is associated with combination of accessor (`get`) and resource name (`hello`). 
    // Accessors are determined by the network protocol.
    // In HTTP resources, function parameters come from query parameters.
    resource function get hello(string name) returns string {
        return "Hello, " + name;
    }

}

Resource Methods

Service objects use remote methods to expose services in procedural style: remote methods are named by verbs.

Service objects use resource methods to expose services in an RESTful style: resources are named by nouns.

Resources are motivated by HTTP, but are general enough also to work for GraphQL. resource methods are a network-oriented generalization of OO getter/setter concept.

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

Service declaration specifies base path for the resource names. The base path is / in this example.

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

Resource method is associated with combination of accessor (get) and resource name (hello). Accessors are determined by the network protocol. In HTTP resources, function parameters come from query parameters.

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

// Service declaration specifies base path for the resource names. The base path is `/` in this example.
service / on new http:Listener(8080) {
    // Resource method is associated with combination of accessor (`get`) and resource name (`hello`). 
    // Accessors are determined by the network protocol.
    // In HTTP resources, function parameters come from query parameters.
    resource function get hello(string name) returns string {
        return "Hello, " + name;
    }

}

Resource Methods

Service objects use remote methods to expose services in procedural style: remote methods are named by verbs.

Service objects use resource methods to expose services in an RESTful style: resources are named by nouns.

Resources are motivated by HTTP, but are general enough also to work for GraphQL. resource methods are a network-oriented generalization of OO getter/setter concept.

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

Service declaration specifies base path for the resource names. The base path is / in this example.

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

Resource method is associated with combination of accessor (get) and resource name (hello). Accessors are determined by the network protocol. In HTTP resources, function parameters come from query parameters.

}
bal run resource_methods.bal
[ballerina/http] started HTTP/WS listener 0.0.0.0:8080
# Run this cURL command to invoke the resource.
curl "localhost:8080/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