pincer_core/
lib.rs

1//! Core types and traits for pincer declarative HTTP client.
2//!
3//! This crate provides the foundational types used by pincer:
4//! - [`Method`] - HTTP method enum
5//! - [`Request`] and [`RequestBuilder`] - HTTP request types
6//! - [`Response`] - HTTP response type
7//! - [`Error`] and [`Result`] - Error handling
8//! - [`HttpClient`] - Core client trait for HTTP execution
9//! - [`PincerClient`] - Extended client trait with base URL support
10//! - [`StatusCode`] - HTTP status codes (re-exported from `http` crate)
11//! - [`header`] - HTTP header names (re-exported from `http` crate)
12//! - [`ToQueryPairs`] - Trait for converting types to query parameter pairs
13//! - [`PathTemplate`] - Original path template for middleware access
14
15mod body;
16mod client;
17mod error;
18mod method;
19mod multipart;
20mod param_meta;
21mod path_template;
22pub mod prelude;
23mod request;
24mod response;
25
26pub use body::{ContentType, from_json, to_form, to_json, to_query_string};
27pub use client::{HttpClient, HttpClientExt, PincerClient};
28pub use error::{DefaultErrorDecoder, Error, ErrorDecoder, Result};
29pub use method::Method;
30pub use multipart::{Form, Part};
31pub use param_meta::{ParamLocation, ParamMeta, ParameterMetadata};
32pub use path_template::PathTemplate;
33pub use request::{Request, RequestBuilder};
34pub use response::Response;
35
36// Re-export http crate types for status codes and headers
37pub use http::{StatusCode, header};
38
39#[cfg(feature = "streaming")]
40pub use client::HttpClientStreaming;
41#[cfg(feature = "streaming")]
42pub use response::streaming::{StreamingBody, StreamingResponse};
43
44/// Trait for types that can be converted to query parameter pairs.
45///
46/// This is automatically implemented by the `#[derive(Query)]` macro.
47///
48/// # Example
49///
50/// ```ignore
51/// use pincer::Query;
52///
53/// #[derive(Query)]
54/// struct SearchParams {
55///     q: String,
56///     #[query(skip_none)]
57///     page: Option<u32>,
58///     #[query(rename = "page_size")]
59///     limit: u32,
60///     #[query(format = "csv")]
61///     tags: Vec<String>,
62/// }
63/// ```
64pub trait ToQueryPairs {
65    /// Convert this type to a vector of key-value pairs for query parameters.
66    fn to_query_pairs(&self) -> Vec<(String, String)>;
67}