Skip to content

Commit

Permalink
Improve usage examples in the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 22, 2017
1 parent 33ad432 commit 9c7597c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 58 deletions.
86 changes: 43 additions & 43 deletions package.json
@@ -1,45 +1,45 @@
{
"name": "gh-got",
"version": "7.0.0",
"description": "Convenience wrapper for Got to interact with the GitHub API",
"license": "MIT",
"repository": "sindresorhus/gh-got",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"got",
"gh",
"github",
"api",
"request",
"http",
"https",
"get",
"url",
"uri",
"util",
"utility"
],
"dependencies": {
"got": "^8.0.0",
"is-plain-obj": "^1.1.0"
},
"devDependencies": {
"ava": "*",
"get-stream": "^3.0.0",
"nock": "^9.1.0",
"xo": "*"
}
"name": "gh-got",
"version": "7.0.0",
"description": "Convenience wrapper for `got` to interact with the GitHub API",
"license": "MIT",
"repository": "sindresorhus/gh-got",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"got",
"gh",
"github",
"api",
"request",
"http",
"https",
"get",
"url",
"uri",
"util",
"utility"
],
"dependencies": {
"got": "^8.0.0",
"is-plain-obj": "^1.1.0"
},
"devDependencies": {
"ava": "*",
"get-stream": "^3.0.0",
"nock": "^9.1.0",
"xo": "*"
}
}
36 changes: 21 additions & 15 deletions readme.md
Expand Up @@ -18,38 +18,44 @@ Instead of:
const got = require('got');
const token = 'foo';

got('https://api.github.com/users/sindresorhus', {
json: true,
headers: {
'accept': 'application/vnd.github.v3+json',
'authorization': `token ${token}`
}
}).then(res => {
console.log(res.body.login);
(async () => {
const {body} = await got('https://api.github.com/users/sindresorhus', {
json: true,
headers: {
'accept': 'application/vnd.github.v3+json',
'authorization': `token ${token}`
}
});

console.log(body.login);
//=> 'sindresorhus'
});
})();
```

You can do:

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

ghGot('users/sindresorhus', {token: 'foo'}).then(res => {
console.log(res.body.login);
(async () => {
const {body} = await ghGot('users/sindresorhus', {token: 'foo'});

console.log(body.login);
//=> 'sindresorhus'
});
})();
```

Or:

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

ghGot('https://api.github.com/users/sindresorhus', {token: 'foo'}).then(res => {
console.log(res.body.login);
(async () => {
const {body} = await ghGot('https://api.github.com/users/sindresorhus', {token: 'foo'});

console.log(body.login);
//=> 'sindresorhus'
});
})();
```


Expand Down

0 comments on commit 9c7597c

Please sign in to comment.