Currently, I am working on building an API using a serverless AWS Lambda Function with ClaudiaJS as my chosen framework. However, I have encountered an issue when attempting to pass a JSON object to the POST route. The problem arises because the contents of request.body are being parsed as a type "string" instead of the expected type "object". In a typical express node.js backend, I would use bodyParser to handle this situation, but unfortunately that is not an option in this case. Any guidance or assistance on how to resolve this would be greatly appreciated :)
I attempted to use JSON.parse(req.body), but it didn't work as expected.
Here is the snippet of code for the POST route:
var ApiBuilder = require('claudia-api-builder'),
api = new ApiBuilder();
module.exports = api;
api.post('/upload', (req, res) => {
return req.body; //Returning the body for debugging purposes
});
When sending the JSON Object to the service using POSTMAN with content-type:application/json
{
"latitude": "52.514818",
"longitude": "13.356101",
"additionalData": "xyc"
}
The issue persists as the returned result is a string instead of an object. This prevents me from properly parsing the data using req.body.latitude to access the value for the latitude field.
"----------------------------641080260577727375179249\r\nContent-Disposition: form-data; name=\"file\"; filename=\"Berlin.json\"\r\nContent-Type: application/json\r\n\r\n{\n \"latitude\": \"52.514818\",\n \"longitude\": \"13.356101\",\n \"additionalData\": \"xyc\"\n}\n\r\n----------------------------641080260577727375179249--\r\n"