1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/// Htpp Methods
///
/// Not supported all methods yet
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum HttpMethods {
    GET,
    POST,
    PUT,
    DELETE,
}

impl HttpMethods {
    /// Convert HttpMethods in &str
    ///
    /// ```
    ///
    /// let method_str = HttpMethods::GET;
    /// assert_eq(method_str.as_str(), "GET")
    /// ```
    pub fn as_str(&self) -> &'static str {
        match self {
            HttpMethods::GET => "GET",
            HttpMethods::POST => "POST",
            HttpMethods::PUT => "PUT",
            HttpMethods::DELETE => "DELETE",
        }
    }
}

/// Convert &str in HttpMethods
///
/// ```
/// let method_str = "GET";
/// assert_eq(get_method_from_str(method_str), HttpMethods::GET)
/// ```
pub fn get_method_from_str(method_str: &str) -> HttpMethods {
    match method_str {
        "GET" => HttpMethods::GET,
        "POST" => HttpMethods::POST,
        "PUT" => HttpMethods::PUT,
        "DELETE" => HttpMethods::DELETE,

        _ => HttpMethods::GET,
    }
}