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
use crate::framework::response::ApiResult; use crate::framework::Environment; use serde::Serialize; use url::Url; pub enum Method { Get, Post, Put, Delete, Patch, } pub trait Endpoint<ResultType = (), QueryType = (), BodyType = ()> where ResultType: ApiResult, QueryType: Serialize, BodyType: Serialize, { fn method(&self) -> Method; fn path(&self) -> String; fn query(&self) -> Option<QueryType> { None } fn body(&self) -> Option<BodyType> { None } fn url(&self, environment: &Environment) -> Url { Url::from(environment).join(&self.path()).unwrap() } fn content_type(&self) -> String { "application/json".to_owned() } }