Plugins
A plugin is middleware with a name, plus optional capabilities it provides to other plugins and request options it adds. You install one with use(), like any middleware; see Middleware for use(), ordering and the context. To build your own, see Writing a plugin.
Built-in plugins
faxios ships six plugins. Each one has its own entry point, which exports the plugin and its types. Neither the package root nor @gcmdev/faxios/plugins re-exports them, and there is no faxios.plugins property.
| Plugin | Import | Adds |
|---|---|---|
authBearer | import { authBearer } from "@gcmdev/faxios/plugins/auth-bearer" | the auth capability |
authenticate | import { authenticate } from "@gcmdev/faxios/plugins/authenticate" | nothing |
forwardTo | import { forwardTo } from "@gcmdev/faxios/plugins/forward-to" | the forward request option |
refreshAuth | import { refreshAuth } from "@gcmdev/faxios/plugins/refresh-auth" | the refreshAuth request option |
retry | import { retry } from "@gcmdev/faxios/plugins/retry" | the retry request option |
timing | import { timing } from "@gcmdev/faxios/plugins/timing" | nothing |
Ordering
Middleware runs in the order it is installed, so where each plugin sits matters:
- Install
timingbeforeretryto measure all tries together, or after it to measure each try. - Install
retrybeforeauthBearerorauthenticateand the credentials are fetched again on every try. - Install
refreshAuthfirst, beforeretryand the credential plugins, so each request refreshes at most once.
Each plugin's page covers how it works with the others.