pub trait RouteHandler: Send + Sync {
// Required method
fn handle(&self, req: &EnrichedRequest) -> Result<IpcResponse, IpcError>;
}Expand description
Trait for implementing HTTP-style route handlers
Implement this trait to create custom route handlers that can be registered with the IpcRouter.
§Example
use dioxus_ipc_bridge::prelude::*;
struct UserHandler;
impl RouteHandler for UserHandler {
fn handle(&self, req: &EnrichedRequest) -> Result<IpcResponse, IpcError> {
let user_id = req.path_param("id").ok_or(IpcError::BadRequest("Missing ID".into()))?;
Ok(IpcResponse::ok(serde_json::json!({
"user_id": user_id
})))
}
}