suddi / claudia-local-api

Command line utility to launch Express local API for claudia-api-builder. Test drive your lambda functions before deployment (https://www.npmjs.com/package/claudia-local-api)
https://www.npmjs.com/package/claudia-local-api
MIT License
15 stars 19 forks source link

POSTing application/x-www-form-urlencoded data causes Claudia to skip parsing the key-values in the body #21

Open riojack opened 6 years ago

riojack commented 6 years ago

Steps to reproduce

  1. Create a simple Claudia API with Claudia API Builder.
  2. Include a route that handles a POST request.
  3. Start the API with claudia-local-api --api-module ./entry_point_file.js.
  4. With cURL, Postman, Insomnia, or some REST tool, do a POST to the route from step 2 and give it a Content-Type of application/x-www-form-urlencoded then add a body of foo=bar&baz=45.
  5. In the request handler function request.post is an empty object. Expected request.post to equal { foo: "bar", baz: 45 }.

I think this is caused by using bodyParser.urlencoded(...), which will is middleware that will cause Express to parse the POST body into a JSON object before Claudia has a chance to handle it.

In the context of an AWS Lambda that is connected to API Gateway, this extra parsing step does not happen. Claudia gets the raw body as a string and not as a JSON object.

suddi commented 4 years ago

Thanks for the report.

But this does seem to be working. I have added another integration test to validate this, please see: https://github.com/suddi/claudia-local-api/blob/master/test/index.js#L995