Key Features
- Zero Dependencies: Only uses Go’s standard library (
net/http,encoding/json) - Single File Output: One self-contained Go file
- Resource-Based API: Intuitive access (
client.Todos.Create()) - Full Type Safety: Complete Go types with proper JSON tags
- SSE Streaming: Built-in
EventStream[T]for server-sent events - Union Types: Proper marshal/unmarshal for discriminated unions
Quick Start
Step 1: Define Your Contract
Step 2: Generate the SDK
Step 3: Use the Generated Client
Generated Code Structure
The generated file contains everything in a single package:Client Configuration
Creating a Client
Available Options
Type System
Type Mapping Reference
Struct Types
Contract struct types generate Go structs with JSON tags:Optional and Nullable Fields
Optional and nullable fields become pointers withomitempty:
Example:
Enum Fields
Enum fields generate as the base type with a comment:Slice and Map Types
Union Types (Discriminated)
Union types generate a struct with pointer fields for each variant, plus marshal/unmarshal methods:Resources and Methods
Resource Pattern
Each contract resource becomes a struct attached to the client:Method Signatures
Generated method signatures follow these patterns:
All methods take
context.Context as the first parameter for cancellation and timeout support.
Streaming (SSE)
For methods with streaming support, the generator creates anEventStream[T] type:
Stream Method Signature
EventStream API
Streaming Usage
Cancellation
Use context cancellation to stop a stream early:Error Handling
Error Type
Generated code includes anError type for API errors:
Checking Errors
Advanced Usage
Custom HTTP Client
Context Usage
Always pass context for proper cancellation and timeout:Concurrent Requests
Complete Example
Server
Client Usage
See Also
- Overview - Introduction to SDK generation
- Python - Generate Python clients
- TypeScript - Generate TypeScript clients
- Types - Contract type system
- REST Transport - Serve your API over REST