native-svc
A lightweight, blocking HTTP client for testing embedded Rust environments in native environments, built on hyper and tokio. It implements the embedded_svc::http::client::Connection trait with TLS support, zero-copy buffering, custom error handling, and synchronous I/O over HTTP bodies.
An HTTP adapter that implements the embedded-svc interface using hyper as the backend.
This library enables HTTP/HTTPS requests with a familiar synchronous API while leveraging the power and robustness of hyper under the hood.
๐ Features
- Synchronous Interface: Simple and familiar API based on
embedded-svc - HTTPS Support: Secure TLS connections via
hyper-tls - Body Handling: Complete support for reading and writing request/response bodies
- HTTP Headers: Full header management with validation
- Error Handling: Detailed and ergonomic error types
- Performance: Built on
hyperandtokiofor optimal performance
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
๐ ๏ธ Usage
Simple GET Request
use HyperHttpConnection;
use Client;
POST Request with JSON
use HyperHttpConnection;
use Client;
use Write;
Error Handling
use ;
๐๏ธ Architecture
The library is organized into modules:
lib.rs: MainHyperHttpConnectionstructure and trait implementationserror.rs: Custom error types with detailed error handling
Implemented Traits
embedded_svc::http::client::Connection: Main interface for HTTP connectionsembedded_svc::io::Read: Reading response bodyembedded_svc::io::Write: Writing request bodyembedded_svc::http::Status: HTTP status accessembedded_svc::http::Headers: HTTP headers access
๐งช Testing
Run tests with:
Note: Integration tests require an Internet connection as they use httpbin.org.
๐ Performance
- Runtime: Uses Tokio with a multi-threaded runtime
- Memory: Default internal buffer of 8KB for write operations
- Connections: HTTPS connections support with connection reuse via
hyper
๐ Security
- Native TLS/SSL support via
hyper-tls
๐ค Contributing
Contributions are welcome! Here's how to contribute:
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Development Guidelines
- Follow Rust naming conventions
- Add tests for new functionality
- Update documentation for public APIs
- Ensure
cargo clippypasses without warnings
๐ License
This project is licensed under MIT. See the LICENSE files for details.
๐ Compatibility
- Rust Version: 1.88.0 or later
- Platforms: All platforms supported by
tokioandhyper - HTTP Versions: HTTP/1.1
๐ Acknowledgments
- The hyper team for their excellent HTTP client
- The embedded-svc team for standardized traits
- The Rust community for the incredible ecosystem
๐ Known Issues
- Limited HTTP/2 support (HTTP/1.1 only currently)
Made with โค๏ธ in Rust