Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Http Extensions
Shared HTTP types and extension traits for clients and servers.
This crate provides common HTTP functionality built on the popular http crate,
including flexible body handling, unified error types, and ergonomic extension traits
for working with HTTP requests and responses.
Core Types
HttpRequestandHttpResponse- Type aliases for requests and responses withHttpBodyHttpRequestBuilder- Builder for constructing HTTP requests with a fluent APIHttpResponseBuilder- Builder for constructing HTTP responses with a fluent APIHttpBody- Flexible body type supporting text, binary, JSON, and streaming contentHttpBodyBuilder- Builder for creating HTTP bodies with memory pool optimizationHttpError- Unified error type with automatic backtraces and recovery classificationRequestHandler- Trait for HTTP middleware and request processing pipelines
Extension Traits
The crate provides extension traits that add convenience methods to standard HTTP types:
StatusExt- Status code validation and recovery classificationRequestExt- Extensions for HTTP requestsResponseExt- Response recovery classification withRetry-AftersupportHttpRequestExt- Request cloning with body supportHeaderMapExt- Header value extraction and parsingHeaderValueExt- Construction ofHeaderValuefromBytesExtensionsExt- Extensions forExtensionsto extract URI template labels
Quick Start
Here’s a complete example showing how to create an HTTP client, build a request, and validate the response:
// Create a body builder for constructing request/response bodies
let body_builder = new_fake;
// Create a fake handler that returns a successful response
// (This uses the `test-util` feature for testing; similar workflow applies to real clients)
let handler = from;
// Build and send an HTTP request using the handler
let response = handler
.request_builder
.get
.header
.fetch
.await?;
// Validate that the response succeeded (returns error for `4xx/5xx` status codes)
let validated_response = response.ensure_success?;
println!;
Note: This example uses the test-util feature to create a FakeHandler for testing.
In production code, you would use a real HTTP client that implements the
RequestHandler trait, but the workflow remains the same: build requests with
HttpRequestBuilder, send them through a handler, and validate responses with
StatusExt::ensure_success.
Integration with the HTTP Ecosystem
This crate builds on the popular http crate rather than inventing new types:
- Uses
http::Requestandhttp::Responseas base types - Reuses
http::Method,http::StatusCode, andhttp::HeaderMap - Implements standard traits like
http_body::Bodyfor ecosystem compatibility - Works seamlessly with other Rust HTTP libraries
Examples
Validating Response Status
// Check if the response succeeded and return an error if not
let validated_response = response.ensure_success?;
Creating Request Bodies
// Create different body types
let text_body = builder.text;
let binary_body = builder.slice;
let empty_body = builder.empty;
Building HTTP Requests
let request = new
.get
.text
.build
.unwrap;
Building HTTP Responses
let response = new
.status
.header
.body
.build
.unwrap;
Building Middleware with RequestHandler
Testing with FakeHandler
The FakeHandler type (available with the test-util feature) lets you mock HTTP responses
for testing without making actual network requests. This is useful for unit testing code
that depends on HTTP clients.
Features
json- Enables JSON serialization/deserialization support viaJsontypetest-util- Enables fake implementations for testing
Memory Management
Bodies created through HttpBodyBuilder use memory pools from bytesbuf to
reduce allocation overhead. When body data is consumed, memory is automatically recycled
for future requests. This makes the crate particularly efficient for high-throughput scenarios.