JacobHsu
11/6/2014 - 9:05 AM

#nodejs #npm - post json with node.js (npm request )

#nodejs #npm - post json with node.js (npm request )

var request = require('request');

var options = {
  uri: 'https://www.googleapis.com/urlshortener/v1/url',
  method: 'POST',
  json: {
    "longUrl": "http://www.google.com/"
  }
};

request(options, function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body.id) // Print the shortened url.
  }
});