Lambda event.body object from browser POST response is of different type

When I console.log(event.body) and perform a POST request by submitting a classical HTML form from the browser through AWS API Gateway->Lambda I get something like a query string:

event.body = first_name=Blabla&last_name=OOOOO&email=oooo%40aaa.com
when running the same function via serverless-offline plugin on my localhost I get:

event.body = {“first_name”:“Blabla”,“last_name”:“OOOOO”,“email”:“oooo@aaa.com”}
which looks like a JSON string.

I used same Node.js version (4.3.2).

Why is there this difference?

Can you explain more about how you’re testing locally? My first though is that you’re sending a JSON object in the body when testing locally which is different to what the browser will send when posting a form.

Have you tried sending first_name=Blabla&last_name=OOOOO&email=oooo%40aaa.com as the body with content type set to application/x-www-form-urlencoded?

1 Like