I am attempting to add an item to an existing dynamodb table using a PUT request. I have tried several variations of the code including using the .put as well as the .putItem functions. When I hard-code the url into the brower I get the following error:
Cannot GET /add-student?student_id=5&name=carl
When I cut the exact url which gave me this error and paste it into an api testing app, Postman, it works perfectly. I am well aware that the error says that I attempted a GET request, but I don't know what is wrong with my code.
Here's my code.
app.put('/add-student', function (req, res) {
var params = {
TableName : "student",
Item:{
"student_id" : {"N": req.query.student_id},
"name" : {"S": req.query.name}
}
}
dynamodb.putItem(params, function(err, data) {
if(err)
console.log(err);
else
console.log(JSON.stringify(data));
});
});
What might be causing this to be interpreted as a get request? Any help is much appreciated.