Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nested routers] Merge/Nest routers easily #935

Open
like-engels opened this issue Dec 19, 2024 · 0 comments
Open

[Nested routers] Merge/Nest routers easily #935

like-engels opened this issue Dec 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@like-engels
Copy link

like-engels commented Dec 19, 2024

Description of the feature

Hey there! I was wondering if it’d be possible to integrate a more poetic way of nesting/merging routes in Poem. Something that feels intuitive and makes people feel right at home. For example, in web servers like FastAPI, there’s an add_router method that lets you nest routers and makes modularizing the codebase super smooth. I know you can already do this in Poem with .nest("", another_router_object), but honestly, it doesn’t feel very poetic.

So, maybe we could add something like nest_router as an alias or helper method for nest to improve the developer experience? Let me know if I’m missing something here. If this idea is supported, I’d love to open a PR and contribute!. 🚀 🤠

Code example (if possible)

Current approach

/// code somewhere over the rainbow
let v1_router = Route::new().nest("api/v1", {
        Route::new().nest("", another_router_somewhere)
    })
    
 /// main
let app = Route::new().nest("",  v1_router);

Proposed API

/// code somewhere over the rainbow
let v1_router = Route::new().nest("api/v1", {
        Route::new().nest_router(another_router_somewhere)
 })
    
 /// main
let app = Route::new().nest_router(v1_router);

I think we can even streamline the route prefix thing a little bit

/// code somewhere over the rainbow
let v1_router = Route::new().prefix("api/v1")
        .nest_router(another_router_somewhere)
        .nest_router(another_router_somewhere2)
        .nest_router(another_router_somewhere3)
    
 /// main
let app = Route::new().nest_router(v1_router);
@like-engels like-engels added the enhancement New feature or request label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant