Node.js - PUT with 'request' module

MonsterWimp757 picture MonsterWimp757 · Jan 28, 2014 · Viewed 34.5k times · Source

I am using the request module in Node.js to do a put request. My code looks like this

var request = require('request');
var data = {foo: "bar", woo: "car"};

request({
   method: 'PUT',
   uri: myURL,
   multipart: [{
       'content-type':'application/json',
       body: JSON.stringify(data) 
   }]
}, function(error, request, body){
   console.log(body);
});

When I run this I get an error:

"Unsupported content with type: application/json"

Answer

user3242466 picture user3242466 · Jan 28, 2014

Just try it like this:

request({ url: url, method: 'PUT', json: {foo: "bar", woo: "car"}}, callback)