如何使用 AWS lambda 函数获取 URL 参数?
How do I get the URL parameters with AWS lambda functions?
我正在为 API 使用 Netlify 函数,除了我需要访问 URL 参数
之外,大多数函数都运行良好
这是我必须获取参数的片段:
func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {
id := request.PathParameters["id"]
...
}
func main() {
lambda.Start(Handler)
}
我有其他功能正常工作,不需要 URL 参数,但无法弄清楚如何让这些功能正常工作,我尝试了多种不同的选择:
https://example.com/endpoint/1
https://example.com/endpoint/id=1
https://example.com/endpoint?id=1
None上面return命中端点时的id路径参数
您可以使用 request.QueryStringParameters["id"]
从查询参数中获取 id
func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {
id := request.QueryStringParameters["id"]
...
}
然后打电话给 https://example.com/endpoint?id=1
我正在为 API 使用 Netlify 函数,除了我需要访问 URL 参数
之外,大多数函数都运行良好这是我必须获取参数的片段:
func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {
id := request.PathParameters["id"]
...
}
func main() {
lambda.Start(Handler)
}
我有其他功能正常工作,不需要 URL 参数,但无法弄清楚如何让这些功能正常工作,我尝试了多种不同的选择:
https://example.com/endpoint/1
https://example.com/endpoint/id=1
https://example.com/endpoint?id=1
None上面return命中端点时的id路径参数
您可以使用 request.QueryStringParameters["id"]
从查询参数中获取 id
func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {
id := request.QueryStringParameters["id"]
...
}
然后打电话给 https://example.com/endpoint?id=1