Mat.Now
Mat.Now

Reputation: 1725

Get req.body in two different ways

I have one question/problem with request in put method if I use this code:

    userFactory.editProduct = function(id) {
    return $http.put('/api/editProduct', id)
}  

and

    router.put('/editProduct', function(req, res){
    var editProduct = req.body._id;
})

I get properly req.body._id but if I use this code:

    userFactory.deleteDescription = function(id) {
    return $http.put('/api/editProduct/' + id)
}

and

    router.put('/editProduct/:id', function(req, res){
    var editProduct = req.body._id;
})

I get empty {}. could you explain/help me what I should do in second case to get properly _id ?

Upvotes: 0

Views: 38

Answers (1)

Volem
Volem

Reputation: 636

At second case, the id is not a body parameter but it's a URL route parameter.

So try accessing the id as;

req.params.id

Upvotes: 2

Related Questions