Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion fern/products/sdks/overview/typescript/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,65 @@ groups:
noSerdeLayer: false
```

<ParamField path="allowCustomFetcher" type="boolean" default="false" toc={true}>
Enables passing a custom fetcher function to the client. The custom fetcher intercepts all SDK HTTP requests and can be used for logging, tracing, metrics, header injection, routing through proxies, custom retries, or other cross-cutting behavior.

```yaml title="generators.yml"
config:
allowCustomFetcher: true
```

Example using a custom fetcher for request logging:

```typescript title="src/wrapper/loggingFetcher.ts"
import { fetcher as defaultFetcher, type FetchFunction } from "../core/fetcher";

export function createLoggingFetcher(): FetchFunction {
return async (args) => {
const start = Date.now();
const headers = {
...(args.headers ?? {}),
"X-Request-Id": globalThis.crypto?.randomUUID?.() ?? `${Date.now()}`
};
const res = await defaultFetcher({ ...args, headers });
const ms = Date.now() - start;
console.log(`${args.method} ${args.url} -> ${res.status} (${ms}ms)`);
return res;
};
}
```

```typescript title="src/wrapper/PlantStoreClient.ts"
import { PlantStoreClient as FernClient } from "../Client";
import { createLoggingFetcher } from "./loggingFetcher";

type FernClientOptions = ConstructorParameters<typeof FernClient>[0];
type Options = Omit<FernClientOptions, "fetcher">;

export class PlantStoreClient extends FernClient {
constructor(options: Options) {
super({
...options,
fetcher: createLoggingFetcher()
});
}
}
```

```typescript
import { PlantStoreClient } from "plant-store-sdk";

const client = new PlantStoreClient({
environment: "https://api.plantstore.com"
});

await client.plants.get("monstera-123");
// Logs: GET /plants/monstera-123 -> 200 (42ms)
```

See [Dynamic authentication](/sdks/generators/typescript/dynamic-authentication) for an example of adding authentication middleware with a custom fetcher.
</ParamField>

<ParamField path="allowExtraFields" type="boolean" toc={true}>
Allow fields that are not defined in object schemas. This only applies to serde.

Expand Down Expand Up @@ -555,4 +614,4 @@ interface ObjectWithLongAndBigInt {
printMyString(myString);
```

</ParamField>
</ParamField>
Loading