November 2018
Beginner
502 pages
10h 22m
English
Let's have a quick look at some code that exposes a promise-based API:
fetch("https://jsonplaceholder.typicode.com/posts") .then(response => response.json()) .then(data => console.log(data)) .catch(json => console.log("error", json));
The code execution flows down as we would read it. We also don't have to do any additional work in the then methods to handle errors. So, this is much nicer than working with callback-based asynchronous code.
In the next section ...
Read now
Unlock full access