Skip to content

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.

PluginImportAdds
authBearerimport { authBearer } from "@gcmdev/faxios/plugins/auth-bearer"the auth capability
authenticateimport { authenticate } from "@gcmdev/faxios/plugins/authenticate"nothing
forwardToimport { forwardTo } from "@gcmdev/faxios/plugins/forward-to"the forward request option
refreshAuthimport { refreshAuth } from "@gcmdev/faxios/plugins/refresh-auth"the refreshAuth request option
retryimport { retry } from "@gcmdev/faxios/plugins/retry"the retry request option
timingimport { timing } from "@gcmdev/faxios/plugins/timing"nothing

Ordering ​

Middleware runs in the order it is installed, so where each plugin sits matters:

  • Install timing before retry to measure all tries together, or after it to measure each try.
  • Install retry before authBearer or authenticate and the credentials are fetched again on every try.
  • Install refreshAuth first, before retry and the credential plugins, so each request refreshes at most once.

Each plugin's page covers how it works with the others.

faxios is provided under the MIT license. Based on axios by Matt Zabriskie and collaborators.