Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - PUT with 'request' module

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"

like image 229
MonsterWimp757 Avatar asked Jan 27 '14 23:01

MonsterWimp757


People also ask

What is request module in node JS?

The request module is used to make HTTP calls. It is the simplest way of making HTTP calls in node. js using this request module. It follows redirects by default. Note: As of Feb 11th, 2020, request is fully deprecated.

How do I POST a request in node JS?

Example code: var request = require('request') var options = { method: 'post', body: postData, // Javascript object json: true, // Use,If you are sending JSON data url: url, headers: { // Specify headers, If any } } request(options, function (err, res, body) { if (err) { console. log('Error :', err) return } console.

Is request module deprecated?

Request isn't really deprecated. It's no longer considering new features or breaking changes, but it is still being maintained. It's safe to use for the foreseeable future, but how good an idea it is to use it is up to the developer.


1 Answers

Just try it like this:

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

like image 144
user3242466 Avatar answered Oct 12 '22 01:10

user3242466