Skip to content

Instantly share code, notes, and snippets.

@pe3
Last active September 12, 2017 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pe3/a96ae6c35d5dc7176d4476ccf2d5ba75 to your computer and use it in GitHub Desktop.
Save pe3/a96ae6c35d5dc7176d4476ccf2d5ba75 to your computer and use it in GitHub Desktop.
quite clean and minimal async http call
const r2 = require('r2')
// asynchronous arrow functions seem to need an explicit return to work properly
const loadUser = async id => { return await r2(`https://jsonplaceholder.typicode.com/users/${id}`).json }
(async function() {
console.log(await loadUser(2))
})()
{
"name": "playing-with-r2",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"r2": "git+https://git@github.com/mikeal/r2.git"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment