Plugins
Plugins are functions that can be used to modify the request, response, error and other parts of the request lifecycle and can be used to define Fetch Schema.
Init
The init function is called before the request is made and any of the internal functions are called. It takes the url
and options
as arguments and is expected to return the modified url
and options
.
Hooks
Hooks are functions that are called at different stages of the request lifecycle. See Hooks for more information.
If more than one plugin is registered, the hooks will be called in the order they are registered.
Schema
You can define a schema for a plugin. This allows you to easily document the api usage using a schema.
You can also pass a prefix
to the createSchema
function to prefix all the routes.
Get options
The getOptions
function allows you to define additional options that can be passed to the fetch function. This is useful when you want to pass options to the plugins that are not part of the BetterFetchPlugin
interface.
Properties
Prop | Type | Default |
---|---|---|
id | string | - |
name | string | - |
description | string | - |
version | string | - |
hooks | FetchHooks<any> | - |
init | (url: string, options?: { cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | CommonHeaders)) | undefined; ... 32 more ...; disableValidation?: boolean | undefined; } | undefined) => Promise<...> | { ...; } | - |
schema | Schema | - |
getOptions | () => ZodType<any, ZodTypeDef, any> | - |