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

Questions about Nested SubRouter #865

Open
coufxr opened this issue Jun 21, 2024 · 1 comment
Open

Questions about Nested SubRouter #865

coufxr opened this issue Jun 21, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@coufxr
Copy link

coufxr commented Jun 21, 2024

I used the following code and found that the sub routes are not nested. What should I do to achieve my goal?

from robyn import Robyn
from robyn import Request, SubRouter

app = Robyn(__file__)

v1 = SubRouter(__name__, prefix="/v1")


@v1.get("/index")
def hello_v1(request: Request):
    """
    Expected routing: /v1/index
    Actual routing: /v1/index
    """
    print(request)
    return "Hello /v1/index!"


hello = SubRouter(__name__, prefix="/hello")


@hello.get("/index")
def hello_v2(request: Request):
    """
    Expected routing: /v1/hello/index
    Actual routing: /hello/index
    """
    print(request)
    return "Hello /v1/hello/index"


word = SubRouter(__name__, prefix="/word")


@word.get("/index")
def hello_v3(request: Request):
    """
    Expected routing: /v1/word/index
    Actual routing: /word/index
    """
    print(request)
    return "Hello /v1/word/index"


hello.include_router(word)
v1.include_router(hello)
v1.include_router(word)
app.include_router(v1)

if __name__ == "__main__":
    app.start(host="127.0.0.1", port=8000)

logger:

INFO:robyn.logger:Added route HttpMethod.GET /v1/index
INFO:robyn.logger:SERVER IS RUNNING IN VERBOSE/DEBUG MODE. Set --log-level to WARN to run in production mode.
INFO:robyn.logger:Added route HttpMethod.GET /hello/index
INFO:robyn.logger:SERVER IS RUNNING IN VERBOSE/DEBUG MODE. Set --log-level to WARN to run in production mode.
INFO:robyn.logger:Added route HttpMethod.GET /word/index
INFO:robyn.logger:Robyn version: 0.56.0
@sansyrox
Copy link
Member

Hey @coufxr 👋

Thanks for making this issue. Robyn, doesn't support nested subrouters as of now. But this is an interesting feature. I would definitely like to implement it 😄

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

Successfully merging a pull request may close this issue.

2 participants