MiddlewareContext
SourceAn instance of this is passed as the fourth parameter to middleware functions.
API
Constructor
new MiddlewareContext(options)
SourceShould not be instantiated manually. This is created by Endpoint
as part of processing a request.
Parameter | Type | Description | |
---|---|---|---|
* | options | __type |
Methods
addFetchStartListener(callback)
SourceListen for the start of the call to fetch
. The callback will be called immediately
after fetch
is called and is passed the Promise
returned by fetch
.
This is useful for middleware like dedupeInFlightRequestsMiddleware
that need access to the fetch
Promise
directly. It can then cache the promise and subsequently pass it to
SkipToResponse to make other calls to an Endpoint
use the same fetch
Response
.
Parameter | Type | Description | |
---|---|---|---|
* | callback | Function | The callback that will be called when fetch starts. It will be passed the |
markResponseDecoded(response,decodedBody)
SourceMark a Response
as decoded.
You likely don't need this; use decodeBody
on Endpoint
instead. This is useful in cases
where you want to bypass the normal Endpoint
decodeBody
functionality (for example in
batchMiddleware
).
Parameter | Type | Description | |
---|---|---|---|
* | response | Response | The response object returned from |
* | decodedBody | Promise<T> | The decoded body extracted from |
notifyFetchStart(fetchPromise)
SourceCalled internally by Endpoint
to notify when fetch
has started.
Should not be called elsewhere.
Parameter | Type | Description | |
---|---|---|---|
* | fetchPromise | Promise<Response> |
Properties
endpoint: Endpoint
The endpoint the middleware is executing within.
execute: Function
Function to re-execute the Endpoint. Accepts no arguments - it replays the request with identical arguments as the first time. This will go through the full middleware cycle again. This is useful for middleware that may replay a request after an initial failure, eg. if user isn't authenticated on initial attempt.
executeOptions: EndpointExecuteOptions
Key | Type | Description | |
---|---|---|---|
headers | HeadersInit|Record | Any headers to add to the request. You can unset default headers that might be specified in the default
| |
paginator | PaginatorInterface|null | The paginator instance to use. This can be provided in the constructor to use by default for all executions of this endpoint or provided for each call to the endpoint. Only applicable if paginationMiddleware has been added to the Endpoint. | |
query | Query | ||
urlArgs | Record |
The original options passed to execute
lastState: null|MiddlewareNextReturn
The state as of when the last middleware in the chain was processed.
This contains the url
, response
, decodedBody
and result
.
requestInit: EndpointRequestInit
The options used to execute the endpoint with