1

I am new to Ballerina, and i want to know if I can find the response status of any url. This is basically to check if the system is up or down.

ThisaruG
  • 3,222
  • 7
  • 38
  • 60
Betty
  • 28
  • 4

1 Answers1

4

Here is a slightly modified version of the Ballerina http client sample to demonstrate how to obtain the response status code.

import ballerina/http;
import ballerina/io;

public function main() {
    http:Client clientEP = new ("http://www.mocky.io");
    var resp = clientEP->get("/v2/5ae082123200006b00510c3d/");
    if (resp is http:Response) {
        var payload = resp.getTextPayload();
        io:println(resp.statusCode); // print http status code
        if (payload is string) {
            io:println(payload);
        } else {
            io:println(payload.detail());
        }
    } else {
        io:println(resp.detail());
    }
}

This sample was taken from here.

ThisaruG
  • 3,222
  • 7
  • 38
  • 60
Dhananjaya
  • 1,510
  • 2
  • 14
  • 19