Skip to content

Commit

Permalink
Fix incorrect usage in the readme examples (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
PopGoesTheWza committed Apr 27, 2020
1 parent 7c5290d commit 16ff82f
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions readme.md
Expand Up @@ -56,6 +56,8 @@ $ npm install got

## Usage

### Promise

```js
const got = require('got');

Expand All @@ -71,6 +73,26 @@ const got = require('got');
})();
```

### JSON

```js
const got = require('got');

(async () => {
const {body} = await got.post('https://httpbin.org/anything', {
json: {
hello: 'world'
},
responseType: 'json'
});

console.log(body.data);
//=> {hello: 'world'}
})();
```

See [JSON mode](#json-mode) for more details.

###### Streams

```js
Expand Down Expand Up @@ -981,6 +1003,25 @@ Returns an async iterator:

See [`options.pagination`](#pagination) for more pagination options.

#### got.paginate.all(url, options?)

Returns a Promise for an array of all results:

```js
(async () => {
const countLimit = 10;

const results = await got.paginate.all('https://api.github.com/repos/sindresorhus/got/commits', {
pagination: {countLimit}
});

console.log(`Printing latest ${countLimit} Got commits (newest to oldest):`);
console.log(results);
})();
```

See [`options.pagination`](#pagination) for more pagination options.

#### got.get(url, options?)
#### got.post(url, options?)
#### got.put(url, options?)
Expand Down Expand Up @@ -1391,11 +1432,13 @@ const got = require('got');
const tunnel = require('tunnel');

got('https://sindresorhus.com', {
agent: tunnel.httpOverHttp({
proxy: {
host: 'localhost'
}
})
agent: {
https: tunnel.httpOverHttp({
proxy: {
host: 'localhost'
}
})
}
});
```

Expand Down

0 comments on commit 16ff82f

Please sign in to comment.