I need to hit an api using "require" npm in node. The api requires raw put data (not put fields). How do I do this using request npm?
example raw put data I need to send:
var body = {
"id": 123,
"squares": [
{
square_id: 345,
color: "#ccc"
},
{
square_id: 777,
color: "#fff"
}
]
}
I'm trying this but it's not working:
request({
method: "PUT",
uri: UPDATE_GAME,
multipart: [{
'content-type': 'application/json',
body: JSON.stringify(body)
}]
}
If you dig into the code, you'll see that for the most basic of POST/PUT operations you can use the json options parameter. It will also do the JSON.stringify() for you - your code becomes simply:
request({
method: "PUT",
uri: UPDATE_GAME,
json: body
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With