实例¶
源码: source/create.ts
got.defaults
¶
options
¶
类型: Options
The options used for this instance.
handlers
¶
类型: Handler[]
An array of handlers. The next
function returns a Promise
or a Request
Got stream.
You execute them directly by calling got(…)
. They are some sort of "global hooks" - these functions are called first. The last handler (it's invisible) is either asPromise
or asStream
, depending on the options.isStream
property.
mutableDefaults
¶
类型: boolean
默认: false
Determines whether got.defaults.options
can be modified.
got.extend(…options, …instances)
¶
Tip:
options
can includehandlers
andmutableDefaults
.
Note:
- Properties that are not enumerable, such as
body
,json
, andform
, will not be merged.
Configure a new got
instance with merged default options. The options are merged with the parent instance's defaults.options
using options.merge(…)
.
Note:
- Handlers can be asynchronous and can return a
Promise
, but never aPromise<Stream>
ifoptions.isStream
istrue
.- Streams must always be handled synchronously.
- In order to perform async work using streams, the
beforeRequest
hook should be used instead.
The recommended approach for creating handlers that can handle both promises and streams is: