Features

Augment with custom code

Extend the generated SDK to provide additional functionality

Pro Feature

This feature is only available on paid plans. Please schedule a demo or email us to get started.

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.

Create a new file src/helper.ts

1export function myHelper(): void {
2 return console.log("Hello world!");
3}

Add src/helper.ts to .fernignore

.fernignore
1# Specify files that shouldn't be modified by Fern
2
3+ src/helper.ts

Consume the helper

Now your users can consume the helper function by importing it from the SDK:

1import { myHelper } from "sdk/helper";
2
3myHelper();

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.

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.

1import { MyClient as FernClient } from "../client"; // alias the Fern generated client
2
3export class MyClient extends FernClient { // extend the Fern generated client
4
5 public myHelper(): void {
6 return console.log("Hello world!");
7 }
8
9}

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.

src/index.ts
1+ export { MyClient } from src/wrapper/MyClient; // instead of `src/Client`

Update .fernignore

Add both the wrapper directory and index.ts to .fernignore.

.fernignore
1+ src/wrapper
2+ src/index.ts

Consume the method

Now your users can consume the helper function by importing it from the SDK:

1client.myHelper()

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.

1- name: fernapi/fern-typescript-node-sdk
2 version: "..."
3 config:
4 extraDependencies:
5 lodash-es: '1.0.0'
6 extraDevDependencies:
7 "@types/lodash-es": '1.0.0'