Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

async/await Example

node v6.17.1
version: 1.2.2
endpointsharetweet
Compares purely Promise-based approach to async/await approach.
Import fetch
const fetch = require("node-fetch");
Promised-based Request
const requestAnimePromise = id => { fetch(`https://jikan.me/api/anime/${id}`) .then(response => response.json()) .then(json => { console.log("Promise-based") console.log(json) }); } requestAnimePromise(1);
async/await based Request
const requestAnimeAwait = async (id=100) => { const response = await fetch(`https://jikan.me/api/anime/${id}`) const json = await response.json(); console.log("async/await based"); console.log(json); } requestAnimeAwait();
Loading…

no comments

    sign in to comment