Skip to content

Fetch #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2020
Merged

Fetch #134

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions 5-network/01-fetch/01-fetch-users/solution.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Untuk mengambil pengguna kita membutuhkan : `fetch('https://api.github.com/users/USERNAME')`.

To fetch a user we need: `fetch('https://api.github.com/users/USERNAME')`.
Jika tanggapan memiliki status `200` panggil `.json()` untuk membaca objek JSON.

If the response has status `200`, call `.json()` to read the JS object.
Sebaliknya, jika sebuah `fetch` gagal, atau tanggapan tidak memiliki status 200, kita akan mengembalikan `null` di senarai hasilnya.

Otherwise, if a `fetch` fails, or the response has non-200 status, we just return `null` in the resulting array.

So here's the code:
Jadi ini kodenya :

```js demo
async function getUsers(names) {
Expand Down Expand Up @@ -33,8 +32,8 @@ async function getUsers(names) {
}
```

Please note: `.then` call is attached directly to `fetch`, so that when we have the response, it doesn't wait for other fetches, but starts to read `.json()` immediately.
Perlu dicatat, panggilan `.then()` terpasang secara langsung dengan `fetch`, jadi saat kita memiliki tanggapan, tidak akan menunggu untuk *fetch* lainnya, tetapi segera mulai membaca `.json()`.

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.
Jika kita menggunakan `await Promise.all(names.map(name => fetch(...)))`, dan memanggil `.json()` di hasilnya, maka akan menunggu semua *fetch* untuk menanggapi. Dengan menambahkan `.json()` untuk masing masing *fetch*, kita dapat memastikan pemanggilan *fetch* individu mulai membaca data sebagai JSON tanpa menunggu satu sama lain.

That's an example of how low-level Promise API can still be useful even if we mainly use `async/await`.
Ini adalah contoh bagaimana *API Promise* tingkat rendah masih bisa digunakan meskipun kita utamanya menggunakan `async / await`.
16 changes: 8 additions & 8 deletions 5-network/01-fetch/01-fetch-users/task.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Fetch users from GitHub
# Fetch pengguna dari GitHub

Create an async function `getUsers(names)`, that gets an array of GitHub logins, fetches the users from GitHub and returns an array of GitHub users.
Buatlah sebuah fungsi *async* `getUsers(names)`, yang akan mendapatkan sebuah senarai dari Github *logins*, ambil pengguna dari Github dan kembalikan sebuah senarai dari pengguna GitHub.

The GitHub url with user information for the given `USERNAME` is: `https://api.github.com/users/USERNAME`.
*Url* Github dengan informasi pengguna yang diberikan nama `USERNAME` : `https://api.github.com/users/USERNAME`.

There's a test example in the sandbox.
ini adalah contoh tes di sandbox.

Important details:
Detail Penting:

1. There should be one `fetch` request per user.
2. Requests shouldn't wait for each other. So that the data arrives as soon as possible.
3. If any request fails, or if there's no such user, the function should return `null` in the resulting array.
1. Harus ada satu permintaan `fetch` untuk setiap pengguna.
2. Permintaan tidak boleh menunggu satu sama lain. Sehingga datanya sampai secepatnya.
3. Jika terdapat permintaan yang gagal, atau pengguna tidak ditemukan, fungsi tersebut harus mengembalikan `null` dalam senarai yang dihasilkan.
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy