ilmen_http/http/requests/
verb.rs

1use std::str::FromStr;
2
3use strum_macros::Display;
4
5use crate::http::errors::http_errors::HttpError;
6
7
8#[derive(PartialEq, Eq, Clone, Copy, Debug, Display)]
9pub enum Verb {
10    POST,
11    GET,
12    PUT,
13    DELETE,
14    PATCH,
15    OPTION
16}
17
18impl FromStr for Verb {
19    type Err = HttpError;
20
21    fn from_str(input: &str) -> Result<Verb, HttpError> {
22        match input {
23            "POST" => Ok(Self::POST),
24            "GET" => Ok(Self::GET),
25            "PUT" => Ok(Self::PUT),
26            "DELETE" => Ok(Self::DELETE),
27            "PATCH" => Ok(Self::PATCH),
28            "OPTIONS" => Ok(Self::OPTION),
29            _ =>  Err(HttpError::BadRequest(format!("Unknown verb: {}", input)))
30        }
31    }
32}