Last active
April 21, 2023 17:13
-
-
Save mikeal/013dbb2ef3810cfe976cbe16ddb11c6f to your computer and use it in GitHub Desktop.
HTTP Client Comparison
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
const r2 = require('r2') | |
let doJsonThing = async (path, propname) => { | |
let res = await r2(`http://api.com${path}`).json | |
return res[propname] | |
} |
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
const request = require('request') | |
let doJsonThing = (path, propname, cb) => { | |
request(`http://api.com${path}`, {json: true}, (err, resp, body) => { | |
if (err) return cb(err) | |
if (resp.statusCode < 200 || resp.statusCode > 299) { | |
return cb(new Error(`Status not 200, ${resp.statusCode}`)) | |
} | |
cb(null, body[propname]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to believe you; I feel like there is something powerful I'm missing. But I don't understand your answer to @bluepnume and @bahmutov.
@jakearchibald: I'll take over the idiot badge ;)