Swan Lake Beta3 is here.
import ballerina/http;
import ballerina/io;

public function main() returns error? {
    // A client object is created by applying `new` to a client class.
    http:Client httpClient = check new ("https://api.github.com/");

    // The remote method calls use the `->` syntax. This enables the sequence diagram view.
    http:Response resp =
                    check httpClient->get("/orgs/ballerina-platform/repos");

    io:println(resp.statusCode);
}

Consuming Services: Client Objects

Ballerina has a language construct called client objects. They are a special kind of objects that contain remote methods in addition to regular methods. remote methods are used to interact with a remote service. Applications typically do not need to write client classes, which are either provided by library modules or generated from some flavor of IDL.

import ballerina/http;
import ballerina/io;
public function main() returns error? {
    http:Client httpClient = check new ("https://api.github.com/");

A client object is created by applying new to a client class.

    http:Response resp =
                    check httpClient->get("/orgs/ballerina-platform/repos");

The remote method calls use the -> syntax. This enables the sequence diagram view.

    io:println(resp.statusCode);
}
bal run consuming_services.bal
200
import ballerina/http;
import ballerina/io;

public function main() returns error? {
    // A client object is created by applying `new` to a client class.
    http:Client httpClient = check new ("https://api.github.com/");

    // The remote method calls use the `->` syntax. This enables the sequence diagram view.
    http:Response resp =
                    check httpClient->get("/orgs/ballerina-platform/repos");

    io:println(resp.statusCode);
}

Consuming Services: Client Objects

Ballerina has a language construct called client objects. They are a special kind of objects that contain remote methods in addition to regular methods. remote methods are used to interact with a remote service. Applications typically do not need to write client classes, which are either provided by library modules or generated from some flavor of IDL.

import ballerina/http;
import ballerina/io;
public function main() returns error? {
    http:Client httpClient = check new ("https://api.github.com/");

A client object is created by applying new to a client class.

    http:Response resp =
                    check httpClient->get("/orgs/ballerina-platform/repos");

The remote method calls use the -> syntax. This enables the sequence diagram view.

    io:println(resp.statusCode);
}
bal run consuming_services.bal
200
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