0

I am using Serverless framework. The method I am using is "GET" but documentation/blogs have examples related to "POST" method. Basically I have cards in my website and each card has id associated with it, so when user clicks on particular card , that id is sent to backend, we fetch data related to that id from database and return it to UI. we can see data related to that card on UI. How can I implement request validation for it ? (do not want to write validation inside lambda function.)

4
  • do I understand correctly that you only want to validate the request parameter "id"? If so, what makes your ID valid? How do you identify a valid ID? Commented Oct 8, 2021 at 17:15
  • @st.huber yeah so in my lambda function i first check whether i am getting an id and then i check data related to that id in my DB, if its not there, its an invalid id. But the question that i have is what all validations can i do for GET method Commented Oct 11, 2021 at 5:36
  • you don't have to validate that an id gets passed. API Gateway will handle that for you. Commented Oct 11, 2021 at 6:26
  • oh okay, apart from that what other validations can be done for a get method ? Thanks for responding , means a lot Commented Oct 11, 2021 at 8:34

1 Answer 1

1

Typically request validation is only really useful for POST requests that send a body formatted in sme way such as JSON. A GET request typically just passes and id within the URL. The path property as a part of the serverless.yml configuration woudl validate the path and id value on its own with no additional work necessary as there is no body to validate. An example of a configuration I mean:

functions:
  params:
    handler: handler.params
    events:
      - httpApi:
          method: GET
          path: /get/for/any/{param}

In this case, if there is any path other than "/get/for/any/" with a value of some type to match {param} at the end as well it will not trigger the Lambda so it is fully validated already

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

1 Comment

hey yes i do have a path which gets id from ui in serverless.yml , just like you have shown , but i am checking it in my lambda function whether it is getting a pathparameter and id as a key in it , so shall i remove that from my lambda function ? would that effect my website ? because if it is getting validated at api-gateway , there is no need to check it in lambda function right ? Thanks for the help , i really appreciate it.

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.