Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Client Generation

reflectapi automatically generates type-safe client libraries for multiple programming languages from your Rust API server. This section covers how to generate and use clients in different languages.

Supported Languages

LanguageStatus
TypeScript✅ Stable
Rust✅ Stable
Python✅ Experiemental

Code Generation Workflow

See demo project setup https://github.com/thepartly/reflectapi/tree/main/reflectapi-demo

  1. Define your API server using reflectapi traits and builder
  2. Generate schema as JSON from your Rust application
  3. Run the CLI to generate client libraries
  4. Use the clients in your applications with full type safety
# Generate schema (from your Rust app)
cargo run  # Your app should save reflectapi-schema.json

# Generate clients
cargo run reflectapi codegen --language typescript --schema reflectapi-schema.json --output clients/typescript
cargo run reflectapi codegen --language python --schema reflectapi-schema.json --output clients/python
cargo run reflectapi codegen --language rust --schema reflectapi-schema.json --output clients/rust

Common Features

All generated clients share these characteristics:

Type Safety

  • Native type definitions for each language
  • Compile-time or runtime type checking
  • IDE support with autocompletion

Extensibility

  • Default base client implementation is provided
  • Which can be replaced or extended with features, such opentelemetry instrumentation or playwrite tracing

Error Handling

  • Structured error types
  • Network error handling

Async Support

  • Modern async/await patterns

Documentation

  • Generated from your Rust documentation
  • Type information in IDE tooltips

HTTP Client Libraries

LanguageHTTP LibraryFeatures
TypeScriptfetch APINative browser/Node.js support
PythonhttpxAsync/sync, HTTP/2, connection pooling
RustreqwestAsync, HTTP/2, TLS, middleware

Serialization

LanguageSerializationValidation
TypeScriptJSON.parse/stringifyRuntime type checking
PythonPydanticSchema validation, type coercion
RustJSON or MessagePack (serde)Compile-time, zero-cost