Skip to main content

apimock_routing/rule_set/rule/when/request/
http_method.rs

1use hyper::Method;
2use serde::Deserialize;
3
4#[derive(Clone, Deserialize, Debug)]
5#[serde(rename_all = "UPPERCASE")]
6pub enum HttpMethod {
7    Get,
8    Post,
9    Put,
10    Delete,
11}
12
13impl HttpMethod {
14    /// is match
15    pub fn is_match(&self, http_method: &Method) -> bool {
16        self.as_str().to_lowercase() == http_method.as_str().to_lowercase()
17    }
18
19    /// as str
20    pub fn as_str(&self) -> &'static str {
21        match self {
22            HttpMethod::Get => "GET",
23            HttpMethod::Post => "POST",
24            HttpMethod::Put => "PUT",
25            HttpMethod::Delete => "DELETE",
26        }
27    }
28}
29
30impl std::fmt::Display for HttpMethod {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        write!(f, "HTTP Method is {}", self.as_str())
33    }
34}