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

// An HTTP client can be configured to communicate through HTTPS as well.
// To secure a client using HTTPS, the client needs to be configured with
// a certificate file of the listener.
// The [`http:ClientSecureSocket`](https://docs.central.ballerina.io/ballerina/http/latest/records/ClientSecureSocket) record
// provides the SSL-related configurations of the client.
http:Client securedEP = check new("https://localhost:9090",
    secureSocket = {
        cert: "../resource/path/to/public.crt"
    }
);

public function main() returns error? {
    string response = check securedEP->get("/foo/bar");
    io:println(response);
}

Client - SSL/TLS

You can use the HTTPS client to connect or interact with an HTTPS listener. Provide the http:ClientSecureSocket configurations to the client to initiate an HTTPS connection.

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

import ballerina/http;
import ballerina/io;
http:Client securedEP = check new("https://localhost:9090",
    secureSocket = {
        cert: "../resource/path/to/public.crt"
    }
);

An HTTP client can be configured to communicate through HTTPS as well. To secure a client using HTTPS, the client needs to be configured with a certificate file of the listener. The http:ClientSecureSocket record provides the SSL-related configurations of the client.

public function main() returns error? {
    string response = check securedEP->get("/foo/bar");
    io:println(response);
}
# As a prerequisite, start a sample service secured with SSL.
# You may need to change the trusted certificate file path.
bal run http_client_ssl_tls.bal
Hello, World!
import ballerina/http;
import ballerina/io;

// An HTTP client can be configured to communicate through HTTPS as well.
// To secure a client using HTTPS, the client needs to be configured with
// a certificate file of the listener.
// The [`http:ClientSecureSocket`](https://docs.central.ballerina.io/ballerina/http/latest/records/ClientSecureSocket) record
// provides the SSL-related configurations of the client.
http:Client securedEP = check new("https://localhost:9090",
    secureSocket = {
        cert: "../resource/path/to/public.crt"
    }
);

public function main() returns error? {
    string response = check securedEP->get("/foo/bar");
    io:println(response);
}

Client - SSL/TLS

You can use the HTTPS client to connect or interact with an HTTPS listener. Provide the http:ClientSecureSocket configurations to the client to initiate an HTTPS connection.

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

import ballerina/http;
import ballerina/io;
http:Client securedEP = check new("https://localhost:9090",
    secureSocket = {
        cert: "../resource/path/to/public.crt"
    }
);

An HTTP client can be configured to communicate through HTTPS as well. To secure a client using HTTPS, the client needs to be configured with a certificate file of the listener. The http:ClientSecureSocket record provides the SSL-related configurations of the client.

public function main() returns error? {
    string response = check securedEP->get("/foo/bar");
    io:println(response);
}
# As a prerequisite, start a sample service secured with SSL.
# You may need to change the trusted certificate file path.
bal run http_client_ssl_tls.bal
Hello, World!
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