flowglad-rs
A Rust client library for the FlowGlad billing API.
Overview
FlowGlad is an open-source billing infrastructure platform. This library provides a type-safe, ergonomic Rust interface to the FlowGlad API, with support for:
- Customer management (create, retrieve, update, list)
- Billing details and subscription information
- Strongly-typed request/response models
- Automatic retries with exponential backoff
- Comprehensive error handling
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Quick Start
use ;
use CreateCustomer;
async
Configuration
Basic Configuration
use Config;
let config = new;
Environment Variables
use Config;
// Reads from FLOWGLAD_API_KEY environment variable
let config = from_env?;
Advanced Configuration
use Config;
use Duration;
let config = builder
.api_key
.timeout
.max_retries
.build?;
Features
Type Safety
The library uses Rust's type system to prevent common mistakes:
use CreateCustomer;
// Compile-time enforcement of required fields
let customer = new
.email
.phone;
Error Handling
Comprehensive error types for robust error handling:
use Error;
match client.customers.get.await
Automatic Retries
The client automatically retries failed requests with exponential backoff for:
- 500 Internal Server Error
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
Configurable via Config::builder().max_retries().
Metadata Support
Store custom key-value data with any resource:
use json;
let customer = client
.customers
.create
.await?;
Examples
The examples/ directory contains comprehensive examples:
basic_customers.rs- CRUD operations for customerscustomer_metadata.rs- Working with metadataerror_handling.rs- Robust error handling patterns
Run an example with:
FLOWGLAD_API_KEY=sk_test_...
API Coverage
Customers
client.customers().create()- Create a new customerclient.customers().get()- Retrieve a customer by external IDclient.customers().update()- Update customer informationclient.customers().list()- List all customersclient.customers().get_billing()- Get billing details for a customer
Testing
Running Tests
# Run unit tests
# Run integration tests (requires API key)
FLOWGLAD_API_KEY=sk_test_...
Environment Setup
For local development, create a .env file:
# Edit .env and add your test API key
Integration tests will automatically load environment variables from .env if it exists.
Design Principles
External ID vs Internal ID
The FlowGlad API uses your system's identifiers (external IDs) for most operations:
// Create with your ID
let customer = client.customers
.create
.await?;
// customer.id is FlowGlad's internal ID (e.g., "cus_abc")
// customer.external_id is your ID ("user_123")
// Use external_id for retrieval and updates
let customer = client.customers.get.await?;
Builder Pattern
All create and update operations use the builder pattern for ergonomic, self-documenting code:
new
.email // Optional fields
.phone // chain naturally
.metadata;
Documentation
Full API documentation is available at docs.rs/flowglad.
Build documentation locally:
Requirements
- Rust 1.70 or later
- Tokio runtime for async support
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Before submitting:
# Run tests
# Check formatting
# Run clippy
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Documentation: docs.rs/flowglad
- API Reference: FlowGlad API Docs
- Issues: GitHub Issues
Acknowledgments
Built for the FlowGlad open-source billing platform.