Извините, что задали очень простой вопрос, я новичок в балерине и не знаю, как с этим справиться. Я скопировал вставленный код в «Создание клиента для службы калькулятора» в балерине Документация , которая:
импорт балерина / 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: слушатель {
порт: 9090};
// Калькулятор службы REST @http: ServiceConfig {basePath:
"/ calculator"} servicehttp: прослушиватель привязки калькулятора служб {
// 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);
} }
Может кто-нибудь помочь мне понять, что я сделал неправильно. Заранее спасибо!