Skip to content

Commit 267cb66

Browse files
szmarczaksindresorhus
authored andcommittedAug 25, 2018
Document the response object (#592)
1 parent d0757da commit 267cb66

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed
 

‎readme.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ It's a `GET` request by default, but can be changed by using different methods o
8989

9090
#### got(url, [options])
9191

92-
Returns a Promise for a `response` object with a `body` property, a `url` property with the request URL or the final URL after redirects, and a `requestUrl` property with the original request URL.
93-
94-
The response object will typically be a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage), however, if returned from the cache it will be a [response-like object](https://github.com/lukechilds/responselike) which behaves in the same way.
95-
96-
The response will also have a `fromCache` property set with a boolean value.
92+
Returns a Promise for a [`response` object](#response) or a [stream](#streams-1) if `options.stream` is set to true.
9793

9894
##### url
9995

@@ -326,6 +322,46 @@ See the [AWS section](#aws) for an example.
326322

327323
**Note**: Modifying the `body` is not recommended because the `content-length` header has already been computed and assigned.
328324

325+
#### Response
326+
327+
The response object will typically be a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage), however, if returned from the cache it will be a [response-like object](https://github.com/lukechilds/responselike) which behaves in the same way.
328+
329+
##### body
330+
331+
Type: `string` `Object` *(depending on `options.json`)*
332+
333+
The result of the request.
334+
335+
##### url
336+
337+
Type: `string`
338+
339+
The request URL or the final URL after redirects.
340+
341+
##### requestUrl
342+
343+
Type: `string`
344+
345+
The original request URL.
346+
347+
##### fromCache
348+
349+
Type: `boolean`
350+
351+
Whether the response was retrieved from the cache.
352+
353+
##### redirectUrls
354+
355+
Type: `Array`
356+
357+
The redirect URLs.
358+
359+
##### retryCount
360+
361+
Type: `number`
362+
363+
The number of times the request was retried.
364+
329365
#### Streams
330366

331367
**Note**: Progress events, redirect events and request/response events can also be used with promises.

0 commit comments

Comments
 (0)