Skip to content

Commit 9c7597c

Browse files
committedNov 22, 2017
Improve usage examples in the readme
1 parent 33ad432 commit 9c7597c

File tree

2 files changed

+64
-58
lines changed

2 files changed

+64
-58
lines changed
 

‎package.json

+43-43
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
{
2-
"name": "gh-got",
3-
"version": "7.0.0",
4-
"description": "Convenience wrapper for Got to interact with the GitHub API",
5-
"license": "MIT",
6-
"repository": "sindresorhus/gh-got",
7-
"author": {
8-
"name": "Sindre Sorhus",
9-
"email": "sindresorhus@gmail.com",
10-
"url": "sindresorhus.com"
11-
},
12-
"engines": {
13-
"node": ">=4"
14-
},
15-
"scripts": {
16-
"test": "xo && ava"
17-
},
18-
"files": [
19-
"index.js"
20-
],
21-
"keywords": [
22-
"got",
23-
"gh",
24-
"github",
25-
"api",
26-
"request",
27-
"http",
28-
"https",
29-
"get",
30-
"url",
31-
"uri",
32-
"util",
33-
"utility"
34-
],
35-
"dependencies": {
36-
"got": "^8.0.0",
37-
"is-plain-obj": "^1.1.0"
38-
},
39-
"devDependencies": {
40-
"ava": "*",
41-
"get-stream": "^3.0.0",
42-
"nock": "^9.1.0",
43-
"xo": "*"
44-
}
2+
"name": "gh-got",
3+
"version": "7.0.0",
4+
"description": "Convenience wrapper for `got` to interact with the GitHub API",
5+
"license": "MIT",
6+
"repository": "sindresorhus/gh-got",
7+
"author": {
8+
"name": "Sindre Sorhus",
9+
"email": "sindresorhus@gmail.com",
10+
"url": "sindresorhus.com"
11+
},
12+
"engines": {
13+
"node": ">=4"
14+
},
15+
"scripts": {
16+
"test": "xo && ava"
17+
},
18+
"files": [
19+
"index.js"
20+
],
21+
"keywords": [
22+
"got",
23+
"gh",
24+
"github",
25+
"api",
26+
"request",
27+
"http",
28+
"https",
29+
"get",
30+
"url",
31+
"uri",
32+
"util",
33+
"utility"
34+
],
35+
"dependencies": {
36+
"got": "^8.0.0",
37+
"is-plain-obj": "^1.1.0"
38+
},
39+
"devDependencies": {
40+
"ava": "*",
41+
"get-stream": "^3.0.0",
42+
"nock": "^9.1.0",
43+
"xo": "*"
44+
}
4545
}

‎readme.md

+21-15
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,44 @@ Instead of:
1818
const got = require('got');
1919
const token = 'foo';
2020

21-
got('https://api.github.com/users/sindresorhus', {
22-
json: true,
23-
headers: {
24-
'accept': 'application/vnd.github.v3+json',
25-
'authorization': `token ${token}`
26-
}
27-
}).then(res => {
28-
console.log(res.body.login);
21+
(async () => {
22+
const {body} = await got('https://api.github.com/users/sindresorhus', {
23+
json: true,
24+
headers: {
25+
'accept': 'application/vnd.github.v3+json',
26+
'authorization': `token ${token}`
27+
}
28+
});
29+
30+
console.log(body.login);
2931
//=> 'sindresorhus'
30-
});
32+
})();
3133
```
3234

3335
You can do:
3436

3537
```js
3638
const ghGot = require('gh-got');
3739

38-
ghGot('users/sindresorhus', {token: 'foo'}).then(res => {
39-
console.log(res.body.login);
40+
(async () => {
41+
const {body} = await ghGot('users/sindresorhus', {token: 'foo'});
42+
43+
console.log(body.login);
4044
//=> 'sindresorhus'
41-
});
45+
})();
4246
```
4347

4448
Or:
4549

4650
```js
4751
const ghGot = require('gh-got');
4852

49-
ghGot('https://api.github.com/users/sindresorhus', {token: 'foo'}).then(res => {
50-
console.log(res.body.login);
53+
(async () => {
54+
const {body} = await ghGot('https://api.github.com/users/sindresorhus', {token: 'foo'});
55+
56+
console.log(body.login);
5157
//=> 'sindresorhus'
52-
});
58+
})();
5359
```
5460

5561

0 commit comments

Comments
 (0)
Please sign in to comment.