cloudflare/framework/
endpoint.rs

1use crate::framework::response::ApiResult;
2use crate::framework::Environment;
3use serde::Serialize;
4use url::Url;
5
6pub enum Method {
7    Get,
8    Post,
9    Put,
10    Delete,
11    Patch,
12}
13
14pub trait Endpoint<ResultType = (), QueryType = (), BodyType = ()>
15where
16    ResultType: ApiResult,
17    QueryType: Serialize,
18    BodyType: Serialize,
19{
20    fn method(&self) -> Method;
21    fn path(&self) -> String;
22    fn query(&self) -> Option<QueryType> {
23        None
24    }
25    fn body(&self) -> Option<BodyType> {
26        None
27    }
28    fn url(&self, environment: &Environment) -> Url {
29        Url::from(environment).join(&self.path()).unwrap()
30    }
31    fn content_type(&self) -> String {
32        "application/json".to_owned()
33    }
34}