Last active
August 29, 2015 14:20
-
-
Save kurtisdunn/38fea259da71b5aab091 to your computer and use it in GitHub Desktop.
Leafly API - NodeJS
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 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