Skip to content

Is it possible to add Sub Trees ? #34

@dinkopehar

Description

@dinkopehar

Hello.

I found your project radix to be really useful and I discovered it because it's used inside Kemal web framework. Although Kemal is great, I'm looking into making my own simple router using your project.

I'm wondering, is there some solution to sub mounting routes ? For example, Starlette framework has support for that.

I tried some solution, but I end up getting a Tree instead of Result:

require "radix"

users_router = Radix::Tree(String).new
pets_router = Radix::Tree(String).new

users_router.add "/", "All Users"
users_router.add "/login", "Login Users"
users_router.add "/logout", "logout Users"

pets_router.add "/", "Pets"
pets_router.add "/:pet", "Specific Pet"

main_router = Radix::Tree(Radix::Tree(String)).new

main_router.add "/users/", users_router
main_router.add "/pets/", pets_router

result = main_router.find "/users/login" # ???

What I was hoping for is that result would return "All Users" instead of Nil. I assume I'm doing a long stretch here but I'm just curious if this is possible.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions