Product OS : Request
Product OS : Request provides a fully featured HTTP request library combining elements of reqwest and hyper for async requests with a series of helper methods to allow for easier usage depending upon your needs for one-time or repeat usage.
What is Product OS?
Product OS is a collection of packages that provide different tools and features that can work together to build products more easily for the Rust ecosystem.
Installation
[]
= "0.0.1"
Pin the version to match the crate Cargo.toml when using path or git dependencies.
Documentation
Full API documentation is available at docs.rs/product-os-request.
Usage
Overview
Product OS : Request provides a fully featured HTTP request library with multiple implementation choices, allowing you to select between reqwest (high-level) or hyper (low-level) backends while maintaining a consistent API.
Features
- Multiple Implementations - Choose between reqwest or hyper backends
- Async HTTP Requests - Built on tokio for high-performance async I/O
- Default HTTPS/TLS - Secure by default using Rustls
- Requester Pattern - Reusable configuration for multiple requests
- Custom Request/Response Types - Type-safe request building and response handling
- Proxy Support - HTTP, HTTPS, and SOCKS5 proxy configuration
- Redirect Policies - Configurable redirect handling
- Certificate Management - Custom trusted certificates support
- Streaming Responses - Optional streaming support for large responses
- no_std Support - Works in no_std environments with alloc
- Comprehensive Documentation - Well-documented with examples
Installation
Using Reqwest (High-Level, More Features)
[]
= { = "0.0.55", = false, = ["std_reqwest"] }
= { = "1", = ["full"] }
Using Hyper (Low-Level, More Control)
[]
= { = "0.0.55", = false, = ["std_hyper"] }
= { = "1", = ["full"] }
Backward Compatible (defaults to reqwest)
[]
= "0.0.55"
= { = "1", = ["full"] }
Quick Start
Simple GET Request (Reqwest)
use ;
async
Simple GET Request (Hyper)
use ;
async
POST with JSON
use ;
use json;
async
Features
Product OS Request supports optional features that can be enabled as needed:
[]
= { = "0.0.55", = ["json", "form", "stream"] }
Feature Flags
No features are enabled by default. You must explicitly choose an implementation.
Core Features (no_std compatible)
| Feature | Description |
|---|---|
uri |
URI type re-exported from product-os-http |
method |
HTTP method enum with serde support |
response |
Response handling with tracing |
request |
Request building (includes method and response) |
Standard Library Features
| Feature | Description |
|---|---|
method_std |
Method enum with std support |
response_std |
Response handling with std support |
request_std |
Request building with std support (includes method_std and response_std) |
std_base |
Combines request_std, response_std, and method_std |
Backend Implementations
| Feature | Description |
|---|---|
std_reqwest |
High-level reqwest-based HTTP client with TLS, cookies, compression |
std_hyper |
Low-level hyper-based HTTP client with Rustls TLS |
std |
Deprecated alias for std_reqwest |
Hyper Optional Add-ons
| Feature | Description |
|---|---|
hyper_timeout |
Request timeouts for the hyper backend (via tower) |
hyper_compression |
Gzip/Brotli compression for the hyper backend (via tower-http) |
hyper_cookies |
Cookie jar support for the hyper backend |
hyper_proxy |
SOCKS5 proxy support for the hyper backend |
std_hyper_full |
Hyper with all optional add-ons enabled |
Content and Streaming
| Feature | Description |
|---|---|
json |
JSON serialization/deserialization via serde_json |
form |
Form-encoded body support via serde_urlencoded |
stream |
Streaming response support |
stream_reqwest |
Streaming with reqwest backend |
stream_hyper |
Streaming with hyper backend |
no_std Support
To use in a no_std environment:
[]
= { = "0.0.55", = false, = ["method", "request"] }
Examples
The library includes comprehensive examples in this README demonstrating common use cases.
Simple GET Request Example
Configuration Options
Requester Configuration
let mut requester = new;
// Timeouts
requester.set_timeout; // Request timeout in ms
requester.set_connect_timeout; // Connection timeout in ms
// Security
requester.force_secure; // HTTPS only
requester.trust_all_certificates; // Certificate validation
// Redirects
use RedirectPolicy;
requester.set_redirect_policy;
// Proxy
use Protocol;
requester.set_proxy;
// Custom certificates
let cert_der = include_bytes!;
requester.add_trusted_certificate_der;
// Default headers
requester.add_header;
Request Building
let mut request = client.new_request;
// Headers
request.add_header;
request.add_header; // marked as sensitive
// Authentication
request.bearer_auth;
// Query parameters
request.add_param;
request.add_param;
// Body
use Bytes;
use BodyBytes;
let body = new;
request.set_body;
Response Handling
let response = client.request.await?;
// Status
let status = response.status_code;
println!;
// Headers
let headers = response.get_headers;
for in headers
// URL (after redirects)
let url = response.response_url;
// Body as text
let text = client.text.await?;
// Body as JSON
let json = client.json.await?;
// Body as bytes
let bytes = client.bytes.await?;
API Documentation
For detailed API documentation, visit docs.rs/product-os-request.
Contributing
Contributions are not currently available but will be available on a public repository soon.
License
This project is licensed under the GNU GPLv3.