speedrun_api/api/
client.rs1use std::error::Error;
2
3use async_trait::async_trait;
4use bytes::Bytes;
5use http::{request::Builder as RequestBuilder, Response};
6use url::Url;
7
8use super::error::ApiError;
9
10pub trait RestClient {
13 type Error: Error + Send + Sync + 'static;
15
16 fn rest_endpoint(&self, endpoint: &str) -> Result<Url, ApiError<Self::Error>>;
20
21 fn has_api_key(&self) -> bool;
23}
24
25pub trait Client: RestClient {
27 fn rest(
29 &self,
30 request: RequestBuilder,
31 body: Vec<u8>,
32 ) -> Result<Response<Bytes>, ApiError<Self::Error>>;
33}
34
35#[async_trait]
38pub trait AsyncClient: RestClient {
39 async fn rest_async(
41 &self,
42 request: RequestBuilder,
43 body: Vec<u8>,
44 ) -> Result<Response<Bytes>, ApiError<Self::Error>>;
45}