Skip to content

Commit a766c14

Browse files
authored
Merge pull request #435 from carlosabud/master
Fetch
2 parents efd631b + ca31ef1 commit a766c14

File tree

4 files changed

+113
-113
lines changed

4 files changed

+113
-113
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
async function getUsers(names) {
3-
/* your code */
3+
/* Tú código aquí */
44
}

5-network/01-fetch/01-fetch-users/solution.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

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

4-
If the response has status `200`, call `.json()` to read the JS object.
4+
Si la respuesta contiene el status `200`, utilizamos el método `.json()` para leer el objeto JS.
55

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

8-
So here's the code:
8+
Código:
99

1010
```js demo
1111
async function getUsers(names) {
@@ -33,8 +33,8 @@ async function getUsers(names) {
3333
}
3434
```
3535

36-
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.
36+
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.
3737

38-
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.
38+
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.
3939

40-
That's an example of how low-level Promise API can still be useful even if we mainly use `async/await`.
40+
Esto es un ejemplo de cómo la API de Promesas puede ser útil aunque mayormente se utilice `async/await`.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Fetch users from GitHub
1+
# Fetch de usuarios de GitHub
22

3-
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.
3+
Crear una función async llamada `getUsers(names)`, que tome como parámetro un arreglo de logins de GitHub, obtenga el listado de usuarios de GitHub indicado y devuelva un arreglo de usuarios de GitHub.
44

5-
The GitHub url with user information for the given `USERNAME` is: `https://github.com/api/users/USERNAME`.
5+
La url de GitHub con la información de usuario especifica `USERNAME` es: `https://github.com/api/users/USERNAME`.
66

7-
There's a test example in the sandbox.
7+
En el ambiente de prueba (sandbox) hay un ejemplo de referencia.
88

9-
Important details:
9+
Detalles a tener en cuenta:
1010

11-
1. There should be one `fetch` request per user.
12-
2. Requests shouldn't wait for each other. So that the data arrives as soon as possible.
13-
3. If any request fails, or if there's no such user, the function should return `null` in the resulting array.
11+
1. Debe realizarse una única petición `fetch` por cada usuario.
12+
2. Para que la información esté disponible lo antes posible las peticiones no deben ejecutarse de una por vez.
13+
3. Si alguna de las peticiones fallara o si el usuario no existiese, la función debe devolver `null` en el resultado del arreglo.

0 commit comments

Comments
 (0)