Skip to content

Instantly share code, notes, and snippets.

@jochemstoel
Forked from JacobHsu/postjson.js
Created November 2, 2016 04:01
Show Gist options
  • Save jochemstoel/b73a7867a1d38c23c1b26c7d885664a2 to your computer and use it in GitHub Desktop.
Save jochemstoel/b73a7867a1d38c23c1b26c7d885664a2 to your computer and use it in GitHub Desktop.
#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.
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment