首页 > 解决方案 > 我可以访问 Ballerina 程序中的资源路径吗?

问题描述

我正在寻找在“getStudentById”资源中动态访问资源的路径。例如,如果服务被称为“ http://localhost:9090/studentfinder/student/0989898 ”。我想要 '/student/0989898' 部分。

 @http:ResourceConfig {
        methods: ["GET"],
        path: "/student/{studentId}"
    }
    getStudentById(endpoint client, http:Request req, string studentId) {
    ...
    }

标签: ballerina

解决方案


您可以从请求对象获取原始路径,如下所示:

req.rawPath

这应该给出您正在寻找的价值。

https://ballerina.io/learn/api-docs/ballerina/http/objects/Request.html


推荐阅读