如何在春季云功能中获取路径参数

发布于 2025-01-23 04:29:35 字数 358 浏览 0 评论 0原文

我有一个使用Spring-Cloud函数编写的Java应用程序,并在AWS lambda中部署,该应用程序连接到AWS API-GATEWAWA,

我有一个“ get” API(例如,/mosplot>/employs/{employeeeiD})输入参数(在这种情况下为{雇员}),并返回与参数相对应的结果(给定员工的员工详细信息)。

我尝试了谷歌搜索,但找不到一种设置此设置的方法,以使我将{雇员}传递给我的spring-cloud-unction代码并采取相应的行动。如何在Java代码中获取参数?

谁能建议如何在API-Gateway设置此问题并在我的Java Lambda代码中获得相同的参数?

谢谢。

I have a java application written using spring-cloud-functions and deployed in aws lambda which connects to aws api-gateway

I have a 'GET' api(let's say /employees/{employeeId}) which takes an input parameter({employeeId} in this case) and returns the result(employee details for the given employeeId) corresponding to the parameter.

I tried googling but could not find a way to set this up such that I get the {employeeId} passed to my spring-cloud-function code and act accordingly. How do I get the parameter in the java code?

Can anyone suggest how to set this up in api-gateway and get the same parameter in my java lambda code?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦幻的味道 2025-01-30 04:29:35

我将REST API与Lambda集成在一起。我们需要将路径参数和查询参数转换为lambda可以消耗的事件对象。

因此,在Integration选项卡中:

​/I.SSTATIC.NET/S5LQG.JPG“ ALT =“映射模板”>

您可以在此处参考以获取详细信息:
aws知识中心

文章逻辑也可以应用于路径参数。

I used REST API with lambda integration. We need to convert the path params and query params to an event object that the lambda can consume.

So here goes, in integration tab:

URL Query String Parameters

Mapping Templates

You can refer here for details:
AWS Knowledge Centre Article

Same logic can be applied to path params as well.

2025-01-30 04:29:35

对于任何类型的请求,我们都可以尝试进行解决方案,我们将获得该请求的URI。

从标头中提取URI提供的弹簧云功能的输入应为消息的类型或其他任何接受

@Bean
public Function<Message<Void>, Message<?>> api(){}

String uri = (String) request.getHeaders().get("uri");

等式标题的消息:
uri: /post /12345

URI模板可用于提取字符串中的参数。

private HashMap<String, String> getPathParameters(String uri, String strUrlTemplate) {
        UriTemplate template = new UriTemplate(strUrlTemplate);
        Map<String, String> parameters = new HashMap<>();
        return new HashMap<>(template.match(uri));
    }

函数接受URI和将在这种情况下

将返回地图的模板

{
    "id":"12345"
}

We can try to do workaround as for any type of request we will getting uri of the request.

Extracting the uri from the headers provided the input for spring cloud function should be of type of Message or any other which accepts headers

@Bean
public Function<Message<Void>, Message<?>> api(){}

String uri = (String) request.getHeaders().get("uri");

For eq:
Uri: /post/12345

Uri Template can be used to extract the parameters in the string

private HashMap<String, String> getPathParameters(String uri, String strUrlTemplate) {
        UriTemplate template = new UriTemplate(strUrlTemplate);
        Map<String, String> parameters = new HashMap<>();
        return new HashMap<>(template.match(uri));
    }

The function accepts uri and the template for that which will be in this case /post/{id}

which will return a map

{
    "id":"12345"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文