minor
This commit is contained in:
parent
e82885055b
commit
207fbe848f
3 changed files with 51 additions and 40 deletions
|
@ -1,10 +1,9 @@
|
|||
|
||||
To fetch a user we need:
|
||||
To fetch a user we need: `fetch('https://api.github.com/users/USERNAME')`.
|
||||
|
||||
1. `fetch('https://api.github.com/users/USERNAME')`.
|
||||
2. If the response has status `200`, call `.json()` to read the JS object.
|
||||
If the response has status `200`, call `.json()` to read the JS object.
|
||||
|
||||
If a `fetch` fails, or the response has non-200 status, we just return `null` in the resulting arrray.
|
||||
Otherwise, if a `fetch` fails, or the response has non-200 status, we just return `null` in the resulting arrray.
|
||||
|
||||
So here's the code:
|
||||
|
||||
|
@ -38,4 +37,4 @@ Please note: `.then` call is attached directly to `fetch`, so that when we have
|
|||
|
||||
If we used `await Promise.all(names.map(name => fetch(...)))`, and call `.json()` on the results, then it would wait for all fetches to respond. By adding `.json()` directly to each `fetch`, we ensure that individual fetches start reading data as JSON without waiting for each other.
|
||||
|
||||
That's an example of how low-level `Promise` API can still be useful even if we mainly use `async/await`.
|
||||
That's an example of how low-level Promise API can still be useful even if we mainly use `async/await`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue