rust_api_calling 1.0.0

A clean, idiomatic Rust HTTP client library with a single core request function and convenient GET/POST wrappers. Features builder pattern configuration, typed responses via serde generics, automatic session/cookie/XSRF management, and structured logging.
Documentation
use std::collections::HashMap;

/// A typed API response that wraps the deserialized body along with
/// HTTP metadata (status code, headers).
///
/// The generic parameter `T` is the type you want the JSON response
/// body deserialized into (e.g., `Post`, `User`, `Vec<Item>`).
#[derive(Debug)]
pub struct ApiResponse<T> {
    /// The HTTP status code (e.g., 200, 201, 404).
    pub status: u16,

    /// All response headers as key-value pairs.
    pub headers: HashMap<String, String>,

    /// The deserialized response body.
    pub body: T,

    /// The raw response body as a string (useful for debugging).
    pub raw_body: String,
}

impl<T> ApiResponse<T> {
    /// Returns `true` if the status code is in the 2xx range.
    pub fn is_success(&self) -> bool {
        (200..300).contains(&self.status)
    }

    /// Gets a specific header value by key (case-insensitive lookup).
    pub fn header(&self, key: &str) -> Option<&String> {
        let key_lower = key.to_lowercase();
        self.headers
            .iter()
            .find(|(k, _)| k.to_lowercase() == key_lower)
            .map(|(_, v)| v)
    }
}