3

I'm running my services in ballerina composer, then I'm using Windows cmd to invoke the service using the curl but cmd is complaining that curl is not a recognized command.

How could I do it in cmd?

Please help.

MLavoie
  • 9,671
  • 41
  • 36
  • 56
MabutaBee
  • 57
  • 3

2 Answers2

2
  1. Create your service file, here it is hello_service.bal.

import ballerina/http;

endpoint http:Listener listener {
    port:9090
};

service<http:Service> hello bind listener {
    sayHello (endpoint caller, http:Request request) {

        http:Response response = new;

        response.setTextPayload("Hello World!\n");

        _ = caller -> respond(response);
    }
}


2. Run it on cmd. ballerina run hello_service.bal
3. Make a new main.bal file.
import ballerina/http;
import ballerina/log;
import ballerina/io;

endpoint http:Client clientEndpoint {
    url: "http://localhost:9090"
};

function main(string... args) {
    // Send a GET request to the Hello World service endpoint.
    var response = clientEndpoint->get("/hello/sayHello");

    match response {
        http:Response resp => {
            io:println(resp.getTextPayload());
        }
        error err => {
            log:printError(err.message, err = err);
        }
    }
}


4. ballerina run main.bal.
5. You can see the result as Hello World! on cmd now.
Nuwan Alawatta
  • 1,812
  • 21
  • 29
  • This would be ideal way if you want to learn ballerina!. By writing your own client. – hYk Aug 15 '18 at 09:22
1

You don't need to use cURL to invoke Ballerina HTTP services. You can use the HTTP client you normally use (e.g., Postman). If you really want to, you can install cURL in Windows as well: https://curl.haxx.se/download.html.

Pubudu
  • 964
  • 1
  • 7
  • 17