Adding custom code
This page covers how to add custom logic, methods, and dependencies to your TypeScript SDK.
.fernignore
file.Adding custom logic
To get started adding custom code:
Adding custom SDK methods
Fern also allows you to add custom methods to the SDK itself (e.g.
client.my_method()
) by inheriting the Fern generated client and then
extending it.
Update generators.yml
configuration
Name your Fern-generated client something like BaseClient
to reflect that this client will be extended.
Adding custom client configuration
The Java SDK generator supports builder extensibility through a template method pattern. By extending the generated builder classes and overriding protected methods, you can customize how your SDK client is configured without modifying generated code.
Common use cases include:
- Dynamic URL construction: Replace placeholders with runtime values (e.g.,
https://api.${DEV_NAMESPACE}.example.com
) - Custom authentication: Implement complex auth flows beyond basic token authentication
- Request transformation: Add custom headers or modify requests globally
How it works
Generated builders use protected methods that can be overridden:
Create a custom client class
Extend the generated base client:
Method reference
Each method serves a specific purpose and is only generated when needed:
Common patterns
Multi-tenant URLs
Dynamic authentication
Request tracking and monitoring
Advanced HTTP client configuration
Requirements
- Fern Java SDK version: 2.39.1 or later
Adding custom dependencies
To add packages that your custom code requires, update your generators.yml
.