I am using Netlify functions for an API, most of which is working perfectly fine, apart from when I am needing to access URL parameters
Here is a snippet of what I have to get the parameter:
func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {
id := request.PathParameters["id"]
...
}
func main() {
lambda.Start(Handler)
}
I have other functions that are working correctly that do not require URL params but cannot figure out how to get these ones working, I have tried multiple different selections:
https://example.com/endpoint/1
https://example.com/endpoint/id=1
https://example.com/endpoint?id=1
None of the above return the id path parameter when hitting the endpoint
You can use request.QueryStringParameters["id"]
to get id from query param
func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {
id := request.QueryStringParameters["id"]
...
}
And call like https://example.com/endpoint?id=1