Skip to main content

auric_runtime/routing/
route.rs

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