fetch, and provides full type inference with a resource-based developer experience.
Key Features
- Runtime Agnostic: Works on Node.js 18+, Bun, and Deno
- Zero Dependencies: Uses native
fetchAPI only - TypeScript-First: Full type inference and autocompletion
- ES Modules: Modern JavaScript with
async/await - SSE Streaming: First-class
AsyncIterablestreaming - npm-Ready: Includes
package.jsonandtsconfig.json
Quick Start
Step 1: Define Your Contract
Step 2: Generate the SDK
Step 3: Install and Use
Generated Code Structure
package.json
tsconfig.json
Client Configuration
Creating a Client
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string? | undefined | Authentication token |
baseURL | string? | Service default | API base URL |
timeout | number? | 60000 | Request timeout in milliseconds |
maxRetries | number? | 2 | Maximum retry attempts |
defaultHeaders | Record<string, string>? | {} | Headers for all requests |
Accessing Config
Type System
Type Mapping Reference
| Contract Type | TypeScript Type |
|---|---|
string | string |
bool | boolean |
int, int8-int64 | number |
uint, uint8-uint64 | number |
float32, float64 | number |
time.Time | string (ISO 8601) |
json.RawMessage | unknown |
any | unknown |
[]T | T[] |
map[string]T | Record<string, T> |
Interface Types
Contract struct types generate TypeScript interfaces:Optional and Nullable Fields
| Contract Definition | TypeScript Type |
|---|---|
| Required field | T |
optional: true | T? (optional property) |
nullable: true | T | null |
| Both optional and nullable | (T | null)? |
Enum Fields
Enum fields generate as union types:Const Fields
Const fields generate as literal types:Array and Record Types
Union Types (Discriminated)
Union types generate as TypeScript union types:Resources and Methods
Resource Pattern
Each contract resource becomes a property on the client:Method Signatures
Methods use camelCase naming:| Contract Method | TypeScript Signature |
|---|---|
Create | create(input: CreateInput): Promise<Todo> |
List | list(): Promise<ListOutput> |
Get | get(input: { id: string }): Promise<Todo> |
Delete | delete(input: { id: string }): Promise<void> |
Calling Methods
Streaming (SSE)
For methods with streaming support, the SDK providesAsyncIterable streams:
Basic Streaming
Stream with Cancellation
Collecting Stream Events
Stream Type
The stream object implementsAsyncIterable and has an AbortController:
Error Handling
Error Types
The SDK defines three error classes:Handling Errors
Automatic Retries
The client automatically retries failed requests:- Network errors
- Timeout errors
Advanced Usage
Custom Headers
Authentication Modes
The SDK supports different authentication modes:Timeout Configuration
Using with Different Runtimes
The SDK works across all modern JavaScript runtimes:Complete Example
Server
Client Usage
Streaming Example
Installation and Distribution
Installing Locally
Publishing to npm
Installing from Git
Using Without npm
The generated code can be used directly in Deno or Bun without npm:See Also
- Overview - Introduction to SDK generation
- Go - Generate Go clients
- Python - Generate Python clients
- Types - Contract type system
- REST Transport - Serve your API over REST