auric_runtime/routing/
route.rs1use crate::{
2 Context,
3 routing::{Path, RouteDef},
4};
5use async_trait::async_trait;
6
7#[async_trait]
8#[allow(unused)]
9pub trait Route {
10 async fn model(&self, ctx: &impl Context, params: &Path<RouteDef>) -> anyhow::Result<bson::Document>;
11 fn name(&self) -> &'static str;
12}
13
14#[cfg(test)]
15mod tests {
16 use super::Route;
17 use crate::{
18 Context,
19 routing::{Path, RouteDef},
20 };
21 use async_trait::async_trait;
22 use bson::doc;
23
24 #[test]
25 fn can_implement_route() {
26 struct MyRoute {}
27
28 #[async_trait]
29 impl Route for MyRoute {
30 async fn model(&self, _ctx: &impl Context, _params: &Path<RouteDef>) -> anyhow::Result<bson::Document> {
31 Ok(doc! {
32 "a": "A",
33 "b": "B",
34 })
35 }
36 fn name(&self) -> &'static str {
37 "my-route"
38 }
39 }
40 }
41}