openapi-rs
A type-safe Rust client library for building, signing, and sending API requests with minimal boilerplate.
Features
- Type-safe API interactions: Leverage Rust's type system for compile-time safety
- Async/await support: Built on Tokio for efficient asynchronous operations
- Environment-based configuration: Easily load configuration from environment variables
- Automatic request signing: Handles authentication and request signing automatically
- Multiple endpoint support: Support for different endpoint types (API, Cloud, HPC, Sync)
- Extensible architecture: Easily add new API endpoints with minimal code
Installation
Add the dependency to your Cargo.toml
:
Or manually add to your Cargo.toml
:
[]
= "0.1.4"
Quick Start
use AnyZoneListRequest;
use OpenApiClient;
use OpenApiConfig;
use HttpBuilder;
use info;
pub async
Configuration
Environment Variables
The library uses the following environment variables for configuration:
OpenApiAppKey=your_app_key
OpenApiAppSecret=your_app_secret
OpenApiEndpoint=https://api.example.com
OpenApiCloudEndpoint=https://cloud.example.com
OpenApiHpcEndpoint=https://hpc.example.com
OpenApiSyncEndpoint=https://sync.example.com
OpenApiUserId=your_user_id
OpenApiZone=your_zone
XYsVersion=your_version
You can create a .env
file in your project root with these variables or set them in your environment.
Manual Configuration
You can also configure the client programmatically:
let config = new
.with_app_key
.with_app_secret
.with_endpoint
.with_cloud_endpoint
.with_hpc_endpoint
.with_user_id
.with_zone;
API Documentation
Implementation Status
Note: Currently, only a subset of API interfaces has been implemented. Additional interfaces will be implemented progressively based on specific requirements. If you need an interface that hasn't been implemented yet, feel free to open an issue or submit a pull request. Alternatively, you can refer to the "Creating Custom API Requests" section below to implement your own interfaces.
Available APIs
The library currently supports the following API categories:
-
Job API: Manage and monitor jobs
AnyZoneListRequest
: List available zonesApiJobGetRequest
: Get job detailsApiJobListRequest
: List jobsAdminJobGetRequest
: Admin-level job operations
-
Storage API: Manage storage resources
-
Merch API: Merchandise-related operations
-
Sync API: Synchronization operations
Creating Custom API Requests
You can create custom API requests by implementing the HttpBuilder
trait:
Examples
Check the examples
directory for complete working examples:
- Zone List Example: Demonstrates how to list available zones
To run an example:
Error Handling
The library uses anyhow
for error handling, providing detailed error information. All API methods return anyhow::Result<T>
which can be handled using standard Rust error handling patterns:
match client.send.await
Contributing
Contributions are welcome! Here's how you can contribute:
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature
- Commit your changes:
git commit -am 'Add my feature'
- Push to the branch:
git push origin feature/my-feature
- Submit a pull request
Development Setup
# Clone the repository
# Copy example environment file and configure it
# Edit .env with your API credentials
# Run tests
License
This project is licensed under either of:
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.