Skip to content

Commit 1397769

Browse files
C17ANViolet-Bora-Lee
authored andcommitted
[fetch] - 과제 번역 #679
1 parent 3496323 commit 1397769

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
async function getUsers(names) {
3-
/* your code */
3+
/* 여기에 코드를 작성하세요. */
44
}

5-network/01-fetch/01-fetch-users/_js.view/test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
describe("getUsers", function() {
22

3-
it("gets users from GitHub", async function() {
4-
let users = await getUsers(['iliakan', 'remy', 'no.such.users']);
5-
assert.equal(users[0].login, 'iliakan');
6-
assert.equal(users[1].login, 'remy');
3+
it('GitHub에서 사용자 정보를 얻어옵니다.', async function() {
4+
let users = await getUsers(["C17AN", "Violet-Bora-Lee", "이런사용자는없습니다"]);
5+
assert.equal(users[0].login, "C17AN");
6+
assert.equal(users[1].login, "Violet-Bora-Lee");
77
assert.equal(users[2], null);
88
});
99

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
To fetch a user we need: `fetch('https://api.github.com/users/USERNAME')`.
2+
fetch를 통해 사용자 정보를 가져오려면 `fetch('https://api.github.com/users/사용자명')`를 사용해야 합니다.
33

4-
If the response has status `200`, call `.json()` to read the JS object.
4+
응답 상태 코드가 `200`이면 `.json()`을 호출해 객체를 읽습니다.
55

6-
Otherwise, if a `fetch` fails, or the response has non-200 status, we just return `null` in the resulting array.
6+
반면 `fetch`가 실패하거나 응답 상태 코드가 200이 아니라면 `null`을 리턴하고 배열에 담아야 합니다.
77

8-
So here's the code:
8+
답안은 아래와 같습니다.
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+
`.then``fetch` 직후 호출되므로 응답이 도착하면 다른 fetch를 기다리는 대신 곧바로 `.json()`으로 응답을 읽기 시작한다는 것을 기억하세요.
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+
`await Promise.all(names.map(name => fetch(...)))`의 반환값을 대상으로 `.json()`을 호출한다면 모든 fetch 응답이 완료되기 전까지 기다려야 합니다. 대신 각 `fetch`마다 `.json()`을 호출하면 다른 fetch 응답을 기다리지 않으면서 JSON 형식으로 데이터를 읽을 수 있습니다.
3939

40-
That's an example of how low-level Promise API can still be useful even if we mainly use `async/await`.
40+
이 예제를 통해 비록 `async-await`을 주로 사용하더라도 여전히 하위 수준의 프라미스(Promise) API가 유용하게 사용될 수 있음을 알 수 있습니다.
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Fetch users from GitHub
1+
# fetch를 사용해 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+
GitHub 사용자 이름이 담긴 배열을 인자로 받는 비동기 함수 `getUsers(names)`를 만든 후, GitHub에서 fetch한 사용자 정보들이 담긴 배열을 반환하는 함수를 만들어 보세요.
44

5-
The GitHub url with user information for the given `USERNAME` is: `https://api.github.com/users/USERNAME`.
5+
`사용자명`에 해당하는 사용자 정보를 가져오려면 GitHub API `https://api.github.com/users/사용자명`에 요청을 보내면 됩니다.
66

7-
There's a test example in the sandbox.
7+
샌드박스에 테스트 코드가 준비되어 있습니다.
88

9-
Important details:
9+
아래 조건들을 지켜 과제를 완수해 보세요.
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. 사용자당 `fetch` 요청은 한 번만 수행해야 합니다.
12+
2. 데이터가 최대한 일찍 도착할 수 있도록 각 요청은 다른 요청의 결과를 기다려서는 안 됩니다.
13+
3. 요청에 실패하거나 존재하지 않는 사용자에 대한 요청을 보냈다면 `null`을 리턴하고 배열 요소에 담아야 합니다.

0 commit comments

Comments
 (0)