Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
f4d2bb4
components
iliakan Apr 2, 2019
e4b78da
Merge branch 'refactor'
iliakan Apr 2, 2019
674c0bd
minor
iliakan Apr 2, 2019
5bb3500
Sketch editor update (no important image changes)
iliakan Apr 5, 2019
82cd110
Fix typo of 'Fetch: Abort'
Apr 9, 2019
bc4e787
typos and improved wording
Apr 11, 2019
fda60e3
abort
iliakan Apr 17, 2019
ed21bb6
Fixed syntax error / typo
candh Apr 17, 2019
eeaaea4
fixes
iliakan Apr 22, 2019
5013b92
Fix name of JavaScript
lex111 Apr 23, 2019
67ef6cd
Replace `Node.JS` with `Node.js`
lex111 Apr 23, 2019
736b3ea
Replace `Github` with `GitHub`
lex111 Apr 23, 2019
18ef4b7
Fix typos
lex111 May 12, 2019
005a39f
fix
iliakan May 15, 2019
8a23acf
added link to exist page
shamilDzhakeev May 16, 2019
12d64c7
Use relative link
lex111 May 16, 2019
429e33d
Grave accent
alfiya-udc May 20, 2019
b9b401d
Grave accent
alfiya-udc May 22, 2019
a8c9a06
Fix typos
KenjiI May 25, 2019
40b93a5
Update article.md
iliakan May 26, 2019
1a7790d
Update article.md
tonchique May 28, 2019
2f2ed5e
Update article.md
tonchique May 28, 2019
c864589
Fix Websocket article typo
skmetaly May 28, 2019
130ce45
Merge pull request #1023 from tonchique/patch-2
iliakan May 28, 2019
4110423
Merge pull request #1022 from tonchique/patch-1
iliakan May 28, 2019
6a7a13b
Fix typos
lex111 May 29, 2019
a133af5
Update article.md
tonchique May 30, 2019
33fca0b
Merge pull request #1003 from alfiya-udc/master
iliakan May 31, 2019
3781a6e
Merge pull request #1026 from tonchique/patch-3
iliakan May 31, 2019
e9e5dfc
fixes, eventSource
iliakan Jun 16, 2019
9a1b879
Promise.allSettled
iliakan Jun 18, 2019
2782459
minor
iliakan Jun 18, 2019
c24b8cc
minor
iliakan Jun 18, 2019
4bc114b
fixes
iliakan Jun 20, 2019
a4f7537
Small typo in article
solar-artificer Jun 21, 2019
075c6c7
fixes
iliakan Jun 25, 2019
c1353c0
fixes
iliakan Jun 26, 2019
a865a6e
minor
iliakan Jun 26, 2019
3c167c4
fixes
iliakan Jun 26, 2019
ae4be57
sketch up, event loop
iliakan Jun 26, 2019
7acba0d
Russian line to english conversion
imanish003 Jun 27, 2019
4a24021
minor
iliakan Jun 29, 2019
c5321d4
updates
iliakan Jul 3, 2019
c36510c
minor
iliakan Jul 3, 2019
7a9858c
minor
iliakan Jul 3, 2019
148e714
minor
iliakan Jul 3, 2019
987b6e3
fixes
iliakan Jul 4, 2019
b4b707b
minor
iliakan Jul 8, 2019
d753ffb
minor
iliakan Jul 8, 2019
a1aa766
minor
iliakan Jul 9, 2019
894b518
change parameter name to the set one
1van0v Jul 11, 2019
b3b83a7
typo in "by no means"
1van0v Jul 11, 2019
f94be7e
Merge pull request #1140 from 1van0v/patch-4
iliakan Jul 11, 2019
2f6d3be
improvements
iliakan Jul 16, 2019
d956560
Update article.md
hzjjg Jul 19, 2019
22ac30c
Update article.md
kolosovsky Jul 26, 2019
1308d8d
images to svg
iliakan Jul 28, 2019
aa652a1
fix typo in 5-network/11-websocket/article.md
lycheeEng Jul 30, 2019
52d69d7
minor
iliakan Jul 30, 2019
87a24cf
Update article.md
iliakan Jul 30, 2019
1586e2d
Merge pull request #1189 from lycheeEng/patch-1
iliakan Jul 31, 2019
bab44d3
fixes
iliakan Aug 2, 2019
2e0eaf1
fixes
iliakan Aug 2, 2019
ddcd572
up
iliakan Aug 2, 2019
43269e5
currying
iliakan Aug 2, 2019
93db205
minor
iliakan Aug 9, 2019
541171b
minor
iliakan Aug 9, 2019
6a41832
minor
iliakan Aug 10, 2019
f81ae3b
minor
iliakan Aug 10, 2019
cb7b530
minor
iliakan Aug 10, 2019
d466c34
minor
iliakan Aug 10, 2019
9615f21
minor
iliakan Aug 10, 2019
eb5fd79
minor
iliakan Aug 10, 2019
6fdddc1
minor
iliakan Aug 10, 2019
3a9e5d1
minor
iliakan Aug 10, 2019
bcb30e8
minor
iliakan Aug 10, 2019
a9c03d2
Embed font to SVG
iliakan Aug 11, 2019
b44cb72
minor
iliakan Aug 11, 2019
5f3826a
minor
iliakan Aug 13, 2019
7d88fad
minor
iliakan Aug 14, 2019
c003e88
minor
iliakan Aug 14, 2019
b6e7f53
minor
iliakan Aug 14, 2019
63bb4bc
minor
iliakan Aug 15, 2019
2578d52
Update task.md
snowcoding Aug 22, 2019
ca369aa
Some minor corrections
Jandoria Aug 31, 2019
a02f538
Is it
Jandoria Aug 31, 2019
b98c7de
there must be exactly the origin there.
Jandoria Sep 1, 2019
d3beca6
Merge pull request #1299 from Jandoria/patch-1
iliakan Sep 2, 2019
98cf2d7
minor
iliakan Sep 2, 2019
19440f5
Fix grammatical errors
anu-rock Oct 3, 2019
f828eaa
Fix minor typos in Server Sent Events lesson
anu-rock Oct 7, 2019
1d0a1e4
minor
iliakan Oct 7, 2019
d9c4f9a
Update article.md
hsnilsson Oct 8, 2019
fd96537
Merge pull request #1422 from anuragbhd/patch-4
iliakan Oct 10, 2019
87072d2
Merge pull request #1425 from henchies/patch-1
iliakan Oct 10, 2019
3390058
re-import images from Sketch (no changes)
iliakan Oct 10, 2019
7f4611d
Update article.md
iliakan Oct 17, 2019
365d147
Fix typo.
carsca Oct 25, 2019
913c81b
Fix syntax error
ogaclejapan Nov 1, 2019
a4dbabc
bug fix on the server
TomSssM Nov 2, 2019
68b0fc5
Fix: typos
kvoncode Nov 19, 2019
a7ff9b4
minor fixes
iliakan Nov 28, 2019
e647d71
re-import images (Sketch update)
iliakan Nov 30, 2019
871c6b8
Fix typo
Jan 15, 2020
0fb05a6
Update article.md
Beginnerds Jan 28, 2020
45fa324
fix: Minor typo and grammar
achianumba Feb 16, 2020
bfd643b
fix typo
baooab Mar 29, 2020
e94f2b9
Update article.md
leviding Apr 9, 2020
8f3bcdb
Update article.md
leviding Apr 9, 2020
609fb46
Update article.md
leviding Apr 10, 2020
401e367
Update article.md
leviding Apr 11, 2020
8d0d4e2
Merge pull request #1857 from leviding/patch-9
iliakan Apr 29, 2020
bdb384b
Merge pull request #1856 from leviding/patch-8
iliakan Apr 29, 2020
93a0d37
Merge pull request #1855 from leviding/patch-7
iliakan Apr 29, 2020
b617cc1
Update folder - 5-network
odsantos May 24, 2020
b2140a8
Update 5-network folder
odsantos May 24, 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
24 changes: 24 additions & 0 deletions 5-network/01-fetch/01-fetch-users/_js.view/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

async function getUsers(names) {
let jobs = [];

for(let name of names) {
let job = fetch(`https://api.github.com/users/${name}`).then(
successResponse => {
if (successResponse.status != 200) {
return null;
} else {
return successResponse.json();
}
},
failResponse => {
return null;
}
);
jobs.push(job);
}

let results = await Promise.all(jobs);

return results;
}
4 changes: 4 additions & 0 deletions 5-network/01-fetch/01-fetch-users/_js.view/source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

async function getUsers(names) {
/* your code */
}
10 changes: 10 additions & 0 deletions 5-network/01-fetch/01-fetch-users/_js.view/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe("getUsers", function() {

it("gets users from GitHub", async function() {
let users = await getUsers(['iliakan', 'remy', 'no.such.users']);
assert.equal(users[0].login, 'iliakan');
assert.equal(users[1].login, 'remy');
assert.equal(users[2], null);
});

});
40 changes: 40 additions & 0 deletions 5-network/01-fetch/01-fetch-users/solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

To fetch a user we need: `fetch('https://api.github.com/users/USERNAME')`.

If the response has status `200`, call `.json()` to read the JS object.

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:

```js demo
async function getUsers(names) {
let jobs = [];

for(let name of names) {
let job = fetch(`https://api.github.com/users/${name}`).then(
successResponse => {
if (successResponse.status != 200) {
return null;
} else {
return successResponse.json();
}
},
failResponse => {
return null;
}
);
jobs.push(job);
}

let results = await Promise.all(jobs);

return results;
}
```

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.

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`.
13 changes: 13 additions & 0 deletions 5-network/01-fetch/01-fetch-users/task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Fetch users from 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.

The GitHub url with user information for the given `USERNAME` is: `https://api.github.com/users/USERNAME`.

There's a test example in the sandbox.

Important details:

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.
Loading