Server URL templating
Server URL templating lets you define base URLs with variable placeholders (e.g., {region}, {environment}) that SDK users can customize at runtime. This is useful for APIs deployed across multiple regions, environments, or custom domains.
Server URL templating is supported for TypeScript, Python, Java, Go, C#, PHP, and Ruby SDK generation.
Generated SDK behavior
Fern generates an environments module that exposes the default URLs for each named server. SDK users can select a pre-defined environment, set URL variables through client options, or pass custom URL strings. Variable names that conflict with existing client options use a serverUrl prefix in the language’s casing convention, such as serverUrlEnvironment.
TypeScript
Python
Java
Go
C#
PHP
Ruby
The generated SDK exposes an Environment object:
SDK users can select an environment, set URL variables, or pass a custom base URL when constructing the client:
The generated SDK exposes an Environment class:
SDK users can select an environment, set URL variables, or pass a custom environment when constructing the client:
The generated SDK exposes an Environment class:
SDK users can select an environment, set URL variables, or build a custom environment:
The generated SDK exposes an Environments variable:
SDK users can set URL variables or pass a custom base URL with functional options:
The generated SDK exposes an Environment class:
SDK users can set URL variables or a custom environment through ClientOptions:
The generated SDK exposes an Environments class:
SDK users can set URL variables or a custom environment as named constructor arguments:
The generated SDK exposes an Environment class:
SDK users can set URL variables or pass a custom base URL as keyword arguments:
Setting up server URL templating
Define URL template variables in your API definition and provide a static fallback URL when SDK users don’t customize variables:
For full configuration details, see Server names and URL templating in OpenAPI.