我是 WebFlux 和 Serverless 的新手。我正在尝试通过 AWS API 网关创建一个无服务器的 REST API。
流程将是 API Gateway --> Lambda --> DynamoDB
为了实现API流程,Spring Cloud Function是最好的选择吗?我发现aws-serverless-java-container无缝完成工作(将事件转换为 http 请求/响应的包装器)
我已经浏览了 http://cloud.spring.io/spring-cloud-function/single/spring-cloud-function.html 的文档以及 https://github.com/spring-cloud/spring-cloud-function 中找到的几个例子。 但我仍然不确定使用 Spring Cloud Function 是否能够实现 API 风格。
@Bean
//How path or query params can be mapped?
public Function<Flux<String>, Flux<String>> getEmployeeDetails() {
// business logic goes here
}
在上面的代码片段中,如何实现 GET 请求/响应模型。如果我的端点有/{dept}/{employee}/{name},Spring云函数如何接受GET请求中的路径参数?
任何指示都会有帮助。
最佳答案
API Gateway 将传入请求的所有数据包装到 APIGatewayProxyRequestEvent 中对象,它有几个属性,比如请求正文、路径和查询参数,或者原始请求的 HTTP 方法。 对于您的用例,您将获得三个路径参数 dept、employee 和 name。
但是,问题是 SpringBootApiGatewayRequestHandler ,它在传入的 APIGatewayProxyRequestEvent 和您的函数之间进行映射,目前仅考虑请求正文,而根本不考虑其他参数。
希望开发者能够在未来解决这个问题。 同时,您可以实现 SpringBootApiGatewayRequestHandler 的修改版本,它考虑所需的参数。 我写了一篇小文章,which covers exactly this topic .
关于Spring Cloud Function-适合REST API吗?如何访问 GET 路径参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51325366/