Skip to content

Commit

Permalink
Merge 356a4b7 into 32e609f
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Feb 15, 2020
2 parents 32e609f + 356a4b7 commit ac6db27
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion readme.md
Expand Up @@ -248,7 +248,35 @@ Default: `'text'`

The parsing method. Can be `'text'`, `'json'` or `'buffer'`.

The promise also has `.text()`, `.json()` and `.buffer()` methods which sets this and the `resolveBodyOnly` option automatically.
The promise also has `.text()`, `.json()` and `.buffer()` methods which return another Got promise for the parsed body.\
It's like setting the options to `{responseType, resolveBodyOnly: true}` but without affecting the main Got promise.\
Example:

```js
(async () => {
const responsePromise = got(url);
const bufferPromise = responsePromise.buffer();
const jsonPromise = responsePromise.json();

const [response, buffer, json] = Promise.all([responsePromise, bufferPromise, jsonPromise]);
// `response` is an instance of Got Response
// `buffer` is an instance of Buffer
// `json` is an object
})();
```

Or if you don't care about the Response object:

```js
(async () => {
const bufferPromise = got(url).buffer();
const jsonPromise = bufferPromise.json();

const [buffer, json] = Promise.all([bufferPromise, jsonPromise]);
// `buffer` is an instance of Buffer
// `json` is an object
})();
```

Example:

Expand Down

0 comments on commit ac6db27

Please sign in to comment.