pub mod response;
pub mod message;
pub mod request;
pub mod error;
use std::{future::Future, pin::Pin};
use std::fmt::Debug;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use self::error::ErrorResponse;
use self::response::{BinaryResponse, SuccessResponse};
#[derive(Debug)]
pub enum HttpMethod {
GET,
POST,
PUT,
DELETE,
}
pub trait RestRouterFunction: Send + Sync + Clone
where
Self: Send + Sync + Clone,
{
fn route(&self, method: HttpMethod, path: String, data: Value, auth_token: Option<String>, connection_id: Option<String>, ip_address: Option<String>) -> Pin<Box<dyn Future<Output = Result<SuccessResponse, ErrorResponse>> + Send>>;
fn route_redirect(&self, path: String, data: Value, auth_token: Option<String>, connection_id: Option<String>) -> Pin<Box<dyn Future<Output = String> + Send>>;
fn route_binary(&self, _method: HttpMethod, _path: String, _data: Value, _auth_token: Option<String>, _connection_id: Option<String>, _ip_address: Option<String>) -> Pin<Box<dyn Future<Output = Result<Option<BinaryResponse>, ErrorResponse>> + Send>> {
Box::pin(async { Ok(None) })
}
}
pub trait SocketRouterFunction<Req, Resp>: Send + Sync + Clone
where
Self: Send + Sync + Clone,
Req: Serialize + for<'de> Deserialize<'de> + Clone + Debug,
Resp: Serialize + for<'de> Deserialize<'de> + Clone + Debug,
{
fn route(&self, msg: Req, connection_id: String) -> Pin<Box<dyn Future<Output = Option<Resp>> + Send>>;
}