From 8cf6bca2b0e6034dfa6ce2a6107f0cda8d9367ba Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Wed, 12 Feb 2020 18:39:51 +0100 Subject: [PATCH 1/4] Update readme.md --- readme.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 9205e2d6c..181db6953 100644 --- a/readme.md +++ b/readme.md @@ -248,7 +248,33 @@ 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 returning the parsed body. It's like settings the `resolveBodyOnly` option 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: From eeb244164dec0b4be0a649a860546a0a20396d53 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Wed, 12 Feb 2020 18:41:31 +0100 Subject: [PATCH 2/4] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 181db6953..7cc8a7bca 100644 --- a/readme.md +++ b/readme.md @@ -248,7 +248,7 @@ Default: `'text'` The parsing method. Can be `'text'`, `'json'` or `'buffer'`. -The promise also has `.text()`, `.json()` and `.buffer()` methods which return another Got promise returning the parsed body. It's like settings the `resolveBodyOnly` option but without affecting the main Got promise. Example: +The promise also has `.text()`, `.json()` and `.buffer()` methods which return another Got promise returning the parsed body. It's like setting the options to `{responseType, resolveBodyOnly: true}` but without affecting the main Got promise. Example: ```js (async () => { From 9e4c18fcbeb243fd550d5cf7a4ee4a92466ededb Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Wed, 12 Feb 2020 18:43:02 +0100 Subject: [PATCH 3/4] Update readme.md --- readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 7cc8a7bca..d6554394c 100644 --- a/readme.md +++ b/readme.md @@ -248,7 +248,9 @@ Default: `'text'` The parsing method. Can be `'text'`, `'json'` or `'buffer'`. -The promise also has `.text()`, `.json()` and `.buffer()` methods which return another Got promise returning the parsed body. It's like setting the options to `{responseType, resolveBodyOnly: true}` but without affecting the main Got promise. Example: +The promise also has `.text()`, `.json()` and `.buffer()` methods which return another Got promise returning the parsed body.\ +It's like setting the options to `{responseType, resolveBodyOnly: true}` but without affecting the main Got promise.\ +Example: ```js (async () => { From 356a4b767eba2c61e950fb9b018892f8067044bb Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Sat, 15 Feb 2020 12:20:32 +0100 Subject: [PATCH 4/4] Update readme.md Co-Authored-By: Sindre Sorhus --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index d6554394c..43e34fb6c 100644 --- a/readme.md +++ b/readme.md @@ -248,7 +248,7 @@ Default: `'text'` The parsing method. Can be `'text'`, `'json'` or `'buffer'`. -The promise also has `.text()`, `.json()` and `.buffer()` methods which return another Got promise returning the parsed body.\ +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: