product-os-request 0.0.55

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.
Documentation
//! HTTP Method enumeration and conversions
//!
//! This module provides the `Method` enum which represents HTTP request methods.

#[cfg(any(feature = "method", feature = "method_std"))]
use serde::{Deserialize, Serialize};

#[cfg(any(feature = "method", feature = "method_std"))]
pub use product_os_http::method::Method as HttpMethod;

/// HTTP request method enumeration
///
/// Represents standard HTTP methods plus an `ANY` variant for wildcards.
#[cfg(any(feature = "method", feature = "method_std"))]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Method {
    /// HTTP GET method
    GET,
    /// HTTP POST method
    POST,
    /// HTTP PATCH method
    PATCH,
    /// HTTP PUT method
    PUT,
    /// HTTP DELETE method
    DELETE,
    /// HTTP TRACE method
    TRACE,
    /// HTTP HEAD method
    HEAD,
    /// HTTP OPTIONS method
    OPTIONS,
    /// HTTP CONNECT method
    CONNECT,
    /// Wildcard for any method
    ANY,
}

#[cfg(any(feature = "method", feature = "method_std"))]
impl Method {
    /// Convert to `product_os_http::Method`
    ///
    /// Converts this `Method` enum to the underlying HTTP library's method type.
    /// The `ANY` variant defaults to `GET`.
    pub fn to_http_method(&self) -> product_os_http::method::Method {
        match self {
            Method::GET => product_os_http::method::Method::GET,
            Method::POST => product_os_http::method::Method::POST,
            Method::PATCH => product_os_http::method::Method::PATCH,
            Method::PUT => product_os_http::method::Method::PUT,
            Method::DELETE => product_os_http::method::Method::DELETE,
            Method::TRACE => product_os_http::method::Method::TRACE,
            Method::HEAD => product_os_http::method::Method::HEAD,
            Method::OPTIONS => product_os_http::method::Method::OPTIONS,
            Method::CONNECT => product_os_http::method::Method::CONNECT,
            Method::ANY => product_os_http::method::Method::GET,
        }
    }

    /// Create from `product_os_http::Method`
    ///
    /// Converts from the underlying HTTP library's method type to this `Method` enum.
    /// Unknown methods default to `ANY`.
    #[allow(clippy::match_ref_pats)]
    pub fn from_http_method(method: &product_os_http::Method) -> Self {
        match method {
            &product_os_http::method::Method::GET => Method::GET,
            &product_os_http::method::Method::POST => Method::POST,
            &product_os_http::method::Method::PATCH => Method::PATCH,
            &product_os_http::method::Method::PUT => Method::PUT,
            &product_os_http::method::Method::DELETE => Method::DELETE,
            &product_os_http::method::Method::TRACE => Method::TRACE,
            &product_os_http::method::Method::HEAD => Method::HEAD,
            &product_os_http::method::Method::OPTIONS => Method::OPTIONS,
            &product_os_http::method::Method::CONNECT => Method::CONNECT,
            _ => Method::ANY,
        }
    }

    /// Parse from string representation
    ///
    /// Creates a `Method` from its string representation.
    /// Unknown method strings default to `ANY`.
    ///
    /// Note: This method is intentionally not implementing `FromStr` trait
    /// to avoid confusion with the standard library trait, as this method
    /// returns a default value instead of an error for unknown strings.
    #[allow(clippy::should_implement_trait)]
    pub fn from_str(method: &str) -> Self {
        match method {
            "GET" => Method::GET,
            "POST" => Method::POST,
            "PATCH" => Method::PATCH,
            "PUT" => Method::PUT,
            "DELETE" => Method::DELETE,
            "TRACE" => Method::TRACE,
            "HEAD" => Method::HEAD,
            "OPTIONS" => Method::OPTIONS,
            "CONNECT" => Method::CONNECT,
            _ => Method::ANY,
        }
    }
}