Skip to content

Instantly share code, notes, and snippets.

@kurtisdunn
Last active August 29, 2015 14:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtisdunn/38fea259da71b5aab091 to your computer and use it in GitHub Desktop.
Save kurtisdunn/38fea259da71b5aab091 to your computer and use it in GitHub Desktop.
Leafly API - NodeJS
var num = Math.floor(Math.random() * 16) + 1
var body = JSON.stringify({
"Page": num,
"Take": 15
});
var options = {
host: 'data.leafly.com',
port: '80',
path: '/strains/cookies-kush',
method: 'GET',
headers: {
'app_id': '<<app_id>>',
'app_key': '<<app_key>>',
'Content-Type': 'application/json',
'Content-Length': body.length
}
}
var req = http.request(options, function(res, err) {
res.setEncoding('utf8');
var body = "";
if (res.statusCode == 503 && !err) {
console.log('Leafly: ', res.statusCode)
} else if (res.statusCode == 403 && !err) {
console.log('Leafly: ', res.statusCode)
} else {
console.log('Leafly: ', res.statusCode);
res.on('data', function(resData) {
body += resData;
});
res.on('end', function() {
var json = JSON.parse(body);
res.send(json)
});
}
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment