obsidian-rs / obsidian

Ergonomic async http framework for reliable and efficient web
MIT License
27 stars 4 forks source link

feat: add new syntactic sugar for nested routes #71

Closed jk-gan closed 4 years ago

jk-gan commented 4 years ago

Previously when we want to use nested route, we have to write:

// declare a nested router
let mut form_router = Router::new();

// declare nested route
form_router.get("/formtest", |ctx: Context| async move {
    ctx.build_file("./test.html").await.ok()
});

// register the nested router to the app
app.use_router("/forms/", form_router);

With the syntactic sugar:

app.scope("form", |router: &mut Router| {
    router.get("/formtest", |ctx: Context| async move {
        ctx.build_file("/.test.html").await.ok()
    });
});