Caller For Rust
English | 简体中文
A flexible, configurable Web API request library built with Rust.
Features
- 🚀 Async Calls: Built on Tokio, supports high concurrency
- ⚙️ Configuration Management: JSON/YAML/TOML config files
- 🔐 Authentication: Multiple auth types with dynamic token support
- 📊 OpenAPI Generation: Generate API documentation automatically
- 🌐 Swagger UI Server: Built-in API testing interface
- 🔄 Hot Reload: Update config without restart
- 📥 File Download: Auto format detection
- 🔁 Retry Mechanism: Exponential backoff retry
Quick Start
Add Dependency
[]
= "0.3.0"
= { = "1.0", = ["full"] }
Basic Usage
use ;
use HashMap;
async
Documentation
| Topic | Description |
|---|---|
| Configuration | Config file format, multi-format support, hot reload |
| Authentication | Auth types, dynamic tokens, runtime updates |
| API Server | Swagger UI, OpenAPI generation, proxy testing |
Authentication
use ;
use ;
// Static token
register_auth?;
// From environment variable
register_auth?;
// Dynamic token (refreshable)
let token = new;
register_auth?;
// Update at runtime
*token.write.unwrap = "refreshed-token".to_string;
API Documentation Server
Enable the server feature for Swagger UI:
[]
= { = "0.3.0", = ["server"] }
# Open http://localhost:8080 for Swagger UI
Configuration Example
caller.json:
API Reference
Core Functions
// Basic API call
call // With retry
call_with_retry // File download
download
ApiResult
let result = call.await?;
result.status_code // HTTP status
result.raw // Raw response string
result.j_obj // JSON Value
result.get // Get JSON value
result.get_as_str // Get as &str
result.get_as_i64 // Get as i64
Retry Configuration
use RetryConfig;
use Duration;
let retry = new
.with_max_retries
.with_base_delay
.with_max_delay;
Examples
# Basic usage
# Combined parameters
# API documentation server
Testing
# Run all tests
# Run with server feature
License
MIT License - see LICENSE file.