如何在 Ballerina 中访问 GET 变量

How to access a GET variable in Ballerina

假设我的服务器收到一个 GET 请求

www.example.com/?hub.mode=subscribe&hub.challenge=1320729329&hub.verify_token=Hello

我想回显 hub.challenge 部分。我怎样才能用芭蕾舞语言做到这一点?

您需要为此使用 @http:QueryParams。请参考以下示例:

import ballerina.net.http;
import ballerina.lang.system;

@http:BasePath {value:"/shop"}
service echo {

    @http:GET{}
    @http:Path {value:"/order"}
    resource echoGet (message m, @http:QueryParam {value:"orderid"}string orderid) {
        system:println("orderid" + orderid);
        reply m;

    }
}

作为 http://localhost:9090/shop/order?orderid=123 的 GET 请求将被设置为变量 orderid,然后您可以在进一步的实施中使用它。 (请注意,为了示例的目的,我使用了 system:println