Lifecycle Hooks in Detail
BeforeRequest
Description: The beforeRequest
hook provides an interception point before the request is dispatched. This is the perfect place to modify the request configuration, such as headers, query parameters, or the request body.
Example:
AfterResponse
Description: This hook is called after a response is received. It can be used for processing and transforming response data, handling global error logging, or implementing response caching mechanisms.
Example:
OnError
Description: The onError
hook is triggered in case of a request failure. It allows for centralized error management, providing opportunities for error logging, recovery strategies like request retries, or token refreshes.
Example:
Finalize
Description: This hook runs after the request completes, regardless of its outcome. It’s suitable for performing cleanup operations, logging request metrics, or any final steps required after a request.
Example: