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.
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.
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);
}
}
ballerina run hello_service.bal
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);
}
}
}
ballerina run main.bal
.
Hello World!
on cmd now.
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.