You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+38-32Lines changed: 38 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -258,6 +258,24 @@ Determines if a `got.HTTPError` is thrown for error responses (non-2xx status co
258
258
259
259
If this is disabled, requests that encounter an error status code will be resolved with the `response` instead of throwing. This may be useful if you are checking for resource availability and are expecting error responses.
260
260
261
+
###### hooks
262
+
263
+
Type: `Object<string, Array<Function>>`<br>
264
+
Default: `{ beforeRequest: [] }`
265
+
266
+
Hooks allow modifications during the request lifecycle. Hook functions may be async and are run serially.
267
+
268
+
###### hooks.beforeRequest
269
+
270
+
Type: `Array<Function>`<br>
271
+
Default: `[]`
272
+
273
+
Called with the normalized request options. Got will make no further changes to the request before it is sent. This is especially useful in conjunction with [`got.extend()`](#instances) and [`got.create()`](advanced-creation.md) when you want to create an API client that uses HMAC-signing.
274
+
275
+
See the [AWS section](#aws) for an example.
276
+
277
+
**Note**: Modifying the `body` is not recommended because the `content-length` header has already been computed and assigned.
278
+
261
279
#### Streams
262
280
263
281
**Note**: Progress events, redirect events and request/response events can also be used with promises.
Requests to AWS services need to have their headers signed. This can be accomplished by using the [`aws4`](https://www.npmjs.com/package/aws4) package. This is an example for querying an ["Elasticsearch Service"](https://aws.amazon.com/elasticsearch-service/) host with a signed request.
650
+
Requests to AWS services need to have their headers signed. This can be accomplished by using the [`aws4`](https://www.npmjs.com/package/aws4) package. This is an example for querying an ["API Gateway"](https://docs.aws.amazon.com/apigateway/api-reference/signing-requests/) with a signed request.
632
651
633
652
```js
634
-
consturl=require('url');
635
653
constAWS=require('aws-sdk');
636
654
constaws4=require('aws4');
637
655
constgot=require('got');
638
-
constconfig=require('./config');
639
-
640
-
// Reads keys from the environment or `~/.aws/credentials`. Could be a plain object.
0 commit comments