Requirements
Before installing the Wacht Rust SDK, ensure you have:- Rust 1.70+ - The SDK requires a recent version of Rust
- Tokio Runtime - Async runtime for Rust
- Valid Wacht API Key - Required for authentication
Adding the Dependency
Add the SDK to yourCargo.toml file:
Environment Variables
The SDK can be configured using environment variables:Your Wacht API key for authentication. This will be sent as a Bearer token.
The base URL of your Wacht frontend (e.g.,
https://your-app.wacht.io)Optional PEM-encoded public key for JWT verification. If not provided, the SDK will fetch it automatically from the
/.well-known/jwk endpoint.Setting Environment Variables
Feature Flags
The SDK supports the following feature flags:axum (default)
Enables Axum middleware support for JWT authentication and permission checking.
AuthLayer- JWT validation middlewarePermissionLayer- Permission checking middleware- Request extractors (
RequireAuth,RequirePermission, etc.) - Integration with Axum 0.8+
Version Compatibility
| SDK Version | Rust Version | Axum Version | Tokio Version |
|---|---|---|---|
| 2.0.x | 1.70+ | 0.8.x | 1.x |
| 1.x.x | 1.65+ | 0.7.x | 1.x |
Verifying Installation
After adding the dependency, verify the installation:Next Steps
Once installed, proceed to:- Quick Start - Get up and running quickly
- Configuration - Detailed configuration options
- Environment Variables - Complete environment setup
Troubleshooting
Common Issues
Error: WACHT_API_KEY must be set
Error: WACHT_API_KEY must be set
Ensure you’ve set the
WACHT_API_KEY environment variable before running your application:Version conflicts with Axum
Version conflicts with Axum
If you’re using Axum in your project, ensure you’re using version 0.8.x to match the SDK:
Cannot find crate 'wacht'
Cannot find crate 'wacht'
Ensure you’ve run
cargo build or cargo update after adding the dependency to your Cargo.toml.