Robyn icon indicating copy to clipboard operation
Robyn copied to clipboard

SubRouter.add_route

Open LIghtJUNction opened this issue 2 months ago • 6 comments

Bug Description

Image

I expected /login to be fine, but it was actually counterintuitive to write it like this

Steps to Reproduce

No response

Your operating system

None

Your Python version (python --version)

None

Your Robyn version

None

Additional Info

No response

LIghtJUNction avatar Oct 15 '25 07:10 LIghtJUNction

@LIghtJUNction

Try this way:

auth_router = SubRouter(__file__, prefix='/api/auth')
@auth_router.post(endpoint="/login")
async def auth_login(request: Request):
    return "Auth Login Endpoint"

app.include_router(auth_router)

thePromger avatar Oct 27 '25 08:10 thePromger

@LIghtJUNction

Try this way:

auth_router = SubRouter(__file__, prefix='/api/auth')
@auth_router.post(endpoint="/login")
async def auth_login(request: Request):
    return "Auth Login Endpoint"

app.include_router(auth_router)

Of course I know how to write this, which means I need to write these functions in one file. I just think it's counterintuitive.

LIghtJUNction avatar Oct 27 '25 08:10 LIghtJUNction

@sansyrox

Users are getting methods suggested from base class in subrouter, which might confuse some, what is the solution to fix that?

  • no option to add routes other than decorators in subRouter

thePromger avatar Oct 27 '25 08:10 thePromger

@sansyrox

Users are getting methods suggested from base class in subrouter, which might confuse some, what is the solution to fix that?

  • no option to add routes other than decorators in subRouter

Because many people have used fastapi before and write with fastapi's habit, they will think it will be very strange.

LIghtJUNction avatar Oct 27 '25 10:10 LIghtJUNction

@LIghtJUNction

Of course I know how to write this, which means I need to write these functions in one file. I just think it's counterintuitive.

Can you give suggestions for some features required, as you have more experience in using fastapi than me i will try to add those.

thePromger avatar Oct 27 '25 14:10 thePromger

@LIghtJUNction

Of course I know how to write this, which means I need to write these functions in one file. I just think it's counterintuitive.

Can you give suggestions for some features required, as you have more experience in using fastapi than me i will try to add those.

Thank you, the function I want most is nested child routes, and when I look at the issue, I find that there seems to be something wrong with path normalization (one more slash and one less slash at the end of the path may bypass the verification). If robyn releases the official version, I will definitely use it.

LIghtJUNction avatar Oct 27 '25 17:10 LIghtJUNction