Expand description
Declarative HTTP client for Rust.
Define HTTP clients using proc-macros with async/await and Tower middleware.
§Example
ⓘ
use pincer::prelude::*;
#[derive(Debug, Deserialize)]
pub struct User {
id: u64,
name: String,
}
#[pincer(url = "https://api.example.com")]
pub trait UserApi {
#[get("/users/{id}")]
async fn get_user(&self, #[path] id: u64) -> pincer::Result<User>;
}
let client = UserApiClientBuilder::default().build()?;
let user = client.get_user(42).await?;See the tutorial for a complete guide.
Re-exports§
pub use tower;pub use percent_encoding;pub use serde_html_form;pub use url;
Modules§
- _tutorial
- Tutorial: Building HTTP Clients with pincer
- header
- HTTP header types
- middleware
- Tower middleware layers for pincer HTTP client.
- prelude
- Prelude module for convenient imports.
Structs§
- ApiClient
- Generic API client wrapper.
- Client
Config - Configuration for the HTTP client.
- Client
Config Builder - Builder for
ClientConfig. - Default
Error Decoder - Default error decoder that always returns
None. - Form
- A multipart form containing multiple parts.
- Hyper
Client - HTTP client using hyper-util with connection pooling, TLS, and middleware support.
- Hyper
Client Builder - Builder for
HyperClient. - Param
Meta - Metadata about a single parameter.
- Parameter
Metadata - All parameter metadata for a method call.
- Part
- A single part in a multipart form.
- Path
Template - The original path template before parameter substitution.
- Request
- An HTTP request with method, URL, headers, optional body, and extensions.
- Request
Builder - Builder for constructing
Requestinstances. - Response
- HTTP response with status, headers, and body.
- Status
Code - An HTTP status code (
status-codein RFC 9110 et al.).
Enums§
- Content
Type - Content type for request bodies.
- Error
- Main error type for pincer operations.
- Method
- HTTP request method.
- Param
Location - Parameter location in the HTTP request.
Traits§
- Error
Decoder - Trait for decoding HTTP error responses into typed errors.
- Http
Client - Core HTTP client trait.
- Http
Client Ext - Extension trait for
HttpClientwith convenience methods. - Pincer
Client - Trait for types that can be used as pincer API clients.
- ToQuery
Pairs - Trait for types that can be converted to query parameter pairs.
Functions§
- from_
json - Deserialize JSON bytes to a value with path-aware error messages.
- to_form
- Serialize a value to form URL-encoded bytes.
- to_json
- Serialize a value to JSON bytes.
- to_
query_ string - Serialize a value to a query string.
Type Aliases§
- Result
- Result type alias using
crate::Error. - Service
Future - Future type for Tower Service implementation.
Attribute Macros§
- delete
- Mark a method as a DELETE request.
- get
- Mark a method as a GET request.
- head
- Mark a method as a HEAD request.
- http
- Mark a method with a custom HTTP method and path.
- options
- Mark a method as an OPTIONS request.
- patch
- Mark a method as a PATCH request.
- pincer
- Mark a trait as a pincer HTTP client.
- post
- Mark a method as a POST request.
- put
- Mark a method as a PUT request.
Derive Macros§
- Query
- Derive the
ToQueryPairstrait for a struct.