Extend the generated SDK to provide additional functionality
The Fern generated SDKs are designed to be extended with custom code. Your custom code can be used to add additional functionality to the SDK and will live in harmony with the generated code.
Custom logic
If you want to provide any logic in your SDK that goes beyond hitting the REST API, you can
do so by leveraging .fernignore
.
Simply add your custom files to the SDK repository and
list them out in .fernignore
. Fern won’t override any files that you add in .fernignore
.
TypeScript
Python
While the examples above only show TypeScript and Python, they can be extrapolated to any language.
Custom SDK methods
Fern also allows you to add custom methods to the SDK itself (e.g. client.my_method()
).
While the specifics are slightly different for each language, the underlying principle is the same: extension. You can inherit the Fern generated client and add whatever methods you want.
TypeScript
Python
Create a new file src/wrapper/MyClient.ts
You can import the Fern generated client from ../client
and alias it to FernClient
.
Next, extend FernClient
and add whatever methods you want.
Export the extended client
Instead of exporting the generated client, export the extended client. To do this,
you will need to update the index.ts
file.
Update .fernignore
Add both the wrapper
directory and index.ts
to .fernignore
.
Consume the method
Now your users can consume the helper function by importing it from the SDK:
See an example from Flatfile using this process in their TypeScript SDK
Custom Dependencies
To add custom dependencies to your generated SDKs, you can update your generators.yml
.