Извините за очень простой вопрос, я новичок в Ballerina и не знаю, как с этим поступить. Я скопировал код в разделе «Создание клиента для службы калькулятора» в документации что такое:
импортная балерина/http; импортная балерина/ио; импортная балерина/бревно;
конечная точка http:Client clientEndpoint { url: "http://localhost:9090" };
функция main(строка... аргументы) {
http:Request req = new; // Set the JSON payload to the message to be sent to the endpoint. json jsonMsg = { a: 15.6, b: 18.9, operation: "add" }; req.setJsonPayload(jsonMsg); var response = clientEndpoint->post("/calculator/operation", request = req); match response { http:Response resp => { var msg = resp.getJsonPayload(); match msg { json jsonPayload => { string resultMessage = "Addition result " + jsonMsg["a"].toString() + " + " + jsonMsg["b"].toString() + " : " + jsonPayload["result"].toString(); io:println(resultMessage); } error err => { log:printError(err.message, err = err); } } } error err => { log:printError(err.message, err = err); } } }
Затем, когда я запускаю приведенную ниже команду в одной консоли
калькулятор бега балерины
и запустите приведенную ниже команду в другой консоли
балерина бежит client.bal
Я получаю следующее сообщение об ошибке:
ошибка: ./client.bal:17:20: недостаточно аргументов при вызове 'post()' компиляция содержит ошибки
Ниже показан пример кода службы
импортная балерина/http;
конечная точка http:Listener listener { порт:9090 };
// Служба REST калькулятора @http:ServiceConfig { basePath: "/calculator" } servicehttp:Service Calculator bind listener {
// Resource that handles the HTTP POST requests that are directed to // the path `/operation` to execute a given calculate operation // Sample requests for add operation in JSON format // `{ "a": 10, "b": 200, "operation": "add"}` // `{ "a": 10, "b": 20.0, "operation": "+"}` @http:ResourceConfig { methods: ["POST"], path: "/operation" } executeOperation(endpoint client, http:Request req) { json operationReq = check req.getJsonPayload(); string operation = operationReq.operation.toString(); any result = 0.0; // Pick first number for the calculate operation from the JSON request float a = 0; var input = operationReq.a; match input { int ivalue => a = ivalue; float fvalue => a = fvalue; json other => {} //error } // Pick second number for the calculate operation from the JSON request float b = 0; input = operationReq.b; match input { int ivalue => b = ivalue; float fvalue => b = fvalue; json other => {} //error } if(operation == "add" || operation == "+") { result = add(a, b); } // Create response message. json payload = { status: "Result of " + operation, result: 0.0 }; payload["result"] = check <float>result; http:Response response; response.setJsonPayload(payload); // Send response to the client. _ = client->respond(response); } }
Может ли кто-нибудь помочь мне понять, что я сделал неправильно. Заранее спасибо!