Created
November 6, 2014 09:05
-
-
Save JacobHsu/8b77abee6787fcd8636c to your computer and use it in GitHub Desktop.
#nodejs #npm - post json with node.js (npm request )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment