My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Showing posts with label mapping. Show all posts
Showing posts with label mapping. Show all posts

Thursday, January 30, 2020

Sending Request Body can be other than JSON in API Gateway in AWS

Can you accept a form request e.g. the classic application/x-www-form-urlencoded body content type. Answer is yes.

You could even use application/xml or any other format from your request but you have to tweak some settings.

Default mapping template in response:
{
    "body" : $input.json('$')
}

Now, if you send a typical application/JSON body…

{
    "foo": "bar"
}

you’ll get is a JSON object under the body key:

{
    "body" : {
       "foo": "bar"
    }
}


Now if you send a different format, say some XML you’ll receive the body key as a string:

{
    "body" : "my request body"
}

However, if you do so then you need your lambda to do the parsing further.

And Ah! ofcourse you need to redeploy your Api gateway after above changes.

Cheers :)