Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stellar Horizon API Client
A robust, production-ready Rust client for interacting with Stellar Horizon API with comprehensive error handling, rate limiting, retry logic, and monitoring.
Features
✅ Robust Error Handling
✅ Rate Limiting
✅ Retry Logic
✅ Request Management
✅ Response Caching (Optional)
✅ Health Monitoring
✅ Logging & Debugging
Installation
Add to your
Cargo.toml:Quick Start
Basic Usage
Custom Configuration
Health Checks
Rate Limiting Info
Architecture
Core Components
HorizonClient - Main client for API interactions
HorizonError - Comprehensive error types
HorizonRateLimiter - Rate limiting with token bucket
RetryConfig & RetryPolicy - Retry management
ResponseCache - Optional caching layer
HorizonHealthChecker - Health monitoring
Configuration
Basic Configuration
Advanced Configuration
Error Handling
Checking Error Type
Retryability
Rate Limiting
Understanding Limits
Rate Limit Statistics
Handling Rate Limits
The client automatically respects rate limits through the
acquire()method:Custom Rate Limiting
Caching
Enable/Disable Caching
Cache Management
Health Monitoring
Periodic Health Checks
###Continuous Monitoring
Retry Strategies
Transient Failures Only
Retries on:
Transient + Server Errors
Also retries on:
All Retryable Errors
Retries on all errors classified as retryable.
No Retry
Logging
Enable Logging
Logging is enabled by default in debug builds. To enable in release:
Example Output
Best Practices
1. Use Connection Pooling
The client uses
reqwest::Clientinternally which handles connection pooling automatically.2. Respect Rate Limits
Always use the public/private Horizon configuration appropriate for your use case.
3. Implement Backoff
Use the retry configuration to implement exponential backoff:
4. Monitor Health
Implement periodic health checks to detect Horizon issues early:
5. Handle Errors Appropriately
Testing
Test Configuration
Test configuration includes:
Troubleshooting
Rate Limited Errors
Problem: Getting 429 Too Many Requests
Solution:
Timeout Errors
Problem: Requests timing out
Solution:
Network Errors
Problem: Connection refused or network unreachable
Solution:
Performance
Dependencies
reqwest- HTTP clienttokio- Async runtimegovernor- Rate limitingmoka- Async cachingchrono- Timestamp handlinglog- Logging facadethiserror- Error handlingserde- JSON serializationuuid- Request ID generationLicense
MIT
References
Closes #23