Skip to main content

Introducing Client Initialization from Configuration in TypeScript SDKs

· 2 min read

We have added support for initializing the TypeScript SDK from JSON configuration files and environment variables to simplify setup and enhance developer experience.

Details

APIMatic's TypeScript SDKs now support two streamlined initialization paths:

  • Configuration-based initialization using a JSON file via Client.fromJsonConfig()
  • Environment-based initialization via Client.fromEnvironment() with values from process.env (Node.js) or a provided object (browser)

This enables environment-specific deployments, secure credential management, and runtime configuration updates without modifying code. In Node.js, you can optionally use .env files with dotenv to load environment variables.

What's New

A pair of new static methods has been added to the Client class:

  • fromJsonConfig(jsonString) reads client configuration from JSON content
  • fromEnvironment(env?: Record<string, string | undefined>) reads client configuration from environment variables (defaults to process.env in Node.js)
import * as path from 'path';
import * as fs from 'fs';
import { Client } from 'your-package-name';

// Provide absolute path for the configuration file
const absolutePath = path.resolve('./config.json');

// Read the configuration file content
const fileContent = fs.readFileSync(absolutePath, 'utf-8');

// Initialize client from JSON configuration content
const client = Client.fromJsonConfig(fileContent);

Sample Configuration File

{
"environment": "production",
"httpClientOptions": {
"timeout": 30000,
"retryConfig": {
"maxNumberOfRetries": 3
},
"proxySettings": {
"address": "https://my.proxy.address",
"port": 8080
}
}
}

Developer Portal Enhancements

Updates have been made to the SDK Infrastructure section to include guidance for TypeScript. You can find detailed instructions for both configuration-based and environment-based initialization, including sample configuration and .env files.

Learn more about Client Initialization from Environment feature