Skip to content

Commit

Permalink
docs: plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Bekacru committed Jul 23, 2024
1 parent 05ec54a commit f8579eb
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions doc/content/docs/plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,41 @@ const { data, error } = await $fetch("https://jsonplaceholder.typicode.com/path"
You can also pass a `prefix` to the `createSchema` function to prefix all the routes.
</Callout>

### 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.

```ts twoslash title="fetch.ts"
import { createFetch, createSchema, BetterFetchPlugin } from "@better-fetch/fetch";
import { z } from "zod";

const plugin = {
id: "my-plugin",
name: "My Plugin",
getOptions() {
return z.object({
onUploadProgress: z.function().args(z.object({
loaded: z.number(),
total: z.number(),
})),
});
},
} satisfies BetterFetchPlugin;

const $fetch = createFetch({
baseUrl: "https://jsonplaceholder.typicode.com",
plugins: [plugin],
});

const { data, error } = await $fetch("https://jsonplaceholder.typicode.com/path", {
onUploadProgress({
loaded,
total,
}) {
console.log(`Uploaded ${loaded} of ${total} bytes`);
},
});
```

### Properties
<AutoTypeTable path="./lib/better-fetch-options.ts" name="BetterFetchPlugin" />

0 comments on commit f8579eb

Please sign in to comment.