Dhaval Rajani
Dhaval Rajani

Reputation: 311

How can we post data using meteor restivus

I am developing API using meteor restivus package and i want to post data and want to save in database. i have done following coding but not able to get posted data at api call.

// made post api using restivus
Restivus.configure({
    useAuth: false,
    prettyJson: true
});
Restivus.addRoute('addorder', {authRequired: true}, {
post:{
    action: function (data) {
        console.log(data); // undefined
        return {status: "success", data: "test"};
    }
}
});

above api i am calling using server side method for that i have done following coding.

 Meteor.methods({
    apiInsert:function (name){
        this.unblock();
        console.log("api insert method");
        var url = "http://localhost:3000/api/addorder";
        var result = HTTP.post(url,{
    data: { "name": name },
    headers:{
          "content-type":"application/json ; charset=UTF-8",
    }
  });

But i am not getting posted data at api function i am getting undefined in data variable. i dont know how to retrieve posted data at api function.

Upvotes: 2

Views: 1634

Answers (1)

JOHNSON QUADRAS
JOHNSON QUADRAS

Reputation: 46

Try using this.bodyParams.

 post:  {
       action: function () {
          return {status: 'success', data: this.bodyParams};
      }

Upvotes: 3

Related Questions