如何在Windows命令提示符中调用Ballerina服务

3
我正在使用Ballerina Composer运行我的服务,接着我使用Windows cmd通过curl调用服务,但是cmd提示curl不是一个可识别的命令。在cmd中该怎么做呢?请帮忙解决。

你尝试过在Ballerina Composer中使用集成的“try it”工具调用服务吗? - pahan
2个回答

2
  1. 创建你的服务文件,这里是 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. 在命令提示符下运行。 ballerina run hello_service.bal
3. 创建一个新的 main.bal 文件。


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. 现在您可以在命令提示符上看到结果为Hello World!



这将是学习Ballerina的理想方式!通过编写自己的客户端。 - hYk

1
您无需使用cURL来调用Ballerina HTTP服务。您可以使用通常使用的HTTP客户端(例如Postman)。如果您真的想要,也可以在Windows上安装cURL:https://curl.haxx.se/download.html

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接