3

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

3
  • godoc.org/github.com/aws/aws-lambda-go/… Commented Apr 10, 2020 at 18:22
  • read the question again, already using APIGatewayProxyRequest Commented Apr 10, 2020 at 18:24
  • The thing you're already using as a field called QueryStringParameters. What exactly do you need clarification on? Commented Apr 10, 2020 at 18:53

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.