Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect usage in the readme examples #1203

Merged
merged 2 commits into from
Apr 27, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 46 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ const got = require('got');
})();
```

And as a JSON client:
PopGoesTheWza marked this conversation as resolved.
Show resolved Hide resolved

```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"}'
szmarczak marked this conversation as resolved.
Show resolved Hide resolved
})();
```

See [JSON mode](#json-mode) for more details.
szmarczak marked this conversation as resolved.
Show resolved Hide resolved

###### Streams

```js
Expand Down Expand Up @@ -981,6 +1001,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 every results:
szmarczak marked this conversation as resolved.
Show resolved Hide resolved

```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 +1430,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