Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fetch#435

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
joaquinelio merged 19 commits intojavascript-tutorial:masterfromcarlosabud:master
Oct 30, 2020
Merged

Fetch#435

Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
19 commits
Select commitHold shift + click to select a range
8a9179f
Merge pull request #1 from javascript-tutorial/master
carlosabudOct 25, 2020
136de82
Article translation
carlosabudOct 25, 2020
67a3e6f
desalineado
joaquinelioOct 25, 2020
9f3605e
alinedo II
joaquinelioOct 25, 2020
8f9776b
alineado III
joaquinelioOct 25, 2020
72a0e11
alineado IV
joaquinelioOct 25, 2020
13e16fa
code review + spellcheck
carlosabudOct 26, 2020
0ac904a
Update task.md
carlosabudOct 26, 2020
e0e6e8d
Update solution.md
carlosabudOct 26, 2020
971a9c5
Update source.js
carlosabudOct 26, 2020
a05a29e
Update source.js
carlosabudOct 26, 2020
fa2e87a
Update source.js
carlosabudOct 26, 2020
5db5c01
Update solution.js
carlosabudOct 26, 2020
0adbb54
Update task.md
carlosabudOct 26, 2020
f9a4eaa
Update solution.md
carlosabudOct 26, 2020
03baafa
Update 5-network/01-fetch/01-fetch-users/solution.md
carlosabudOct 27, 2020
7240e96
Update 5-network/01-fetch/01-fetch-users/solution.md
carlosabudOct 27, 2020
cb28605
Update solution.js
carlosabudOct 27, 2020
ca31ef1
Update source.js
carlosabudOct 27, 2020
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
2 changes: 1 addition & 1 deletion5-network/01-fetch/01-fetch-users/_js.view/source.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@

async function getUsers(names) {
/*your code */
/*Tú código aquí */
}
14 changes: 7 additions & 7 deletions5-network/01-fetch/01-fetch-users/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@

To fetch a user we need: `fetch('https://api.github.com/users/USERNAME')`.
Para obtener un usuario tenemos que ejecutar el siguiente código: `fetch('https://api.github.com/users/USERNAME')`.

If the response hasstatus `200`,call`.json()`to read the JS object.
Si la respuesta contiene elstatus `200`,utilizamos el método`.json()`para leer el objeto JS.

Otherwise, if a `fetch`fails, or the response has non-200status, we just return`null`in the resulting array.
Por el contrario, si el `fetch`falla o la respuesta no contiene unstatus 200, devolvemos`null`en el resultado del arreglo.

So here's the code:
Código:

```js demo
async function getUsers(names) {
Expand DownExpand Up@@ -33,8 +33,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.
Nota: la función`.then`está directamente vinculada al`fetch`. Por lo tanto, cuando se obtiene la respuesta se procede a ejecutar la función`.json()`inmediatamente en lugar de esperar a las otras peticiones.

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.
Si en su lugar utilizáramos`await Promise.all(names.map(name => fetch(...)))` y llamamos a la función`.json()`sobre los resultados, entonces esperaríamos a que todos las peticiones fetch completen antes de obtener una respuesta. Al agregar `.json()`directamente en cada `fetch`,nos aseguramos de que las peticiones se procesen de manera independiente obteniendo una mejor respuesta en nuestra aplicación.

That's an example of how low-level Promise APIcan still be useful even if we mainly use `async/await`.
Esto es un ejemplo de cómo la APIde Promesas puede ser útil aunque mayormente se utilice `async/await`.
16 changes: 8 additions & 8 deletions5-network/01-fetch/01-fetch-users/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
# Fetchusers from GitHub
# Fetchde usuarios de GitHub

Create anasyncfunction `getUsers(names)`,that gets an array of GitHublogins, fetches the users fromGitHuband returns an array of GitHub users.
Crear una funciónasyncllamada `getUsers(names)`,que tome como parámetro un arreglo delogins de GitHub, obtenga el listado de usuarios deGitHubindicado y devuelva un arreglo de usuarios de GitHub.

The GitHuburlwith user information for the given`USERNAME`is: `https://api.github.com/users/USERNAME`.
Laurlde GitHub con la información de usuario especifica`USERNAME`es: `https://api.github.com/users/USERNAME`.

There's a test example in thesandbox.
En el ambiente de prueba (sandbox) hay un ejemplo de referencia.

Important details:
Detalles a tener en cuenta:

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.Debe realizarse una única petición`fetch`por cada usuario.
2.Para que la información esté disponible lo antes posible las peticiones no deben ejecutarse de una por vez.
3.Si alguna de las peticiones fallara o si el usuario no existiese, la función debe devolver `null`en el resultado del arreglo.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp