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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proposal] router parameters #61

Closed
laith43d opened this issue Jan 5, 2021 · 1 comment
Closed

[proposal] router parameters #61

laith43d opened this issue Jan 5, 2021 · 1 comment
Labels
design API design enhancement New feature or request
Milestone

Comments

@laith43d
Copy link

laith43d commented Jan 5, 2021

Hi vitalik,

This project is magical, I cannot imagine myself developing APIs using anything else from now on, I'm actually in the process of migrating two projects to Ninja already! 馃檪

I have an enhancement proposal for the router, I repetitively configure each route for auth, tags, response, etc. if it is possible to configure these generally in the router.

Examples:
instead of

staff_router = Router()


@staff.get('/orders',
           tags=['staff'],
           auth=IsAuthorized(staff_auth),
           response={200: List[InventoryOrderSchemaOut]}
           )

@staff.get ...

we do

staff = Router(
           tags=['staff'],
           auth=IsAuthorized('STAFF'),
)


@staff.get('/orders',
           response={200: List[InventoryOrderSchemaOut]}
           )
@vitalik
Copy link
Owner

vitalik commented Jan 5, 2021

Hi @aith43d

Thank you! glad to hear this

Indeed, I have also experience some issues with with routers tagging

but the approach of dealing with this I think a bit different - the api.add_router should have these options...

for you case it can be something like this:

from some_module import staff # router

api = NinjaAPI()

api.add_router("/staff", staff, auth=IsAuthorized('STAFF'), tags=["staff"])

@vitalik vitalik added design API design enhancement New feature or request labels Jan 5, 2021
@vitalik vitalik changed the title Thanks and enhancement proposal [proposal] router parameters Jan 5, 2021
@vitalik vitalik added this to the 0.11 milestone Jan 15, 2021
@vitalik vitalik mentioned this issue Feb 9, 2021
vitalik added a commit that referenced this issue Mar 23, 2021
@vitalik vitalik closed this as completed Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design API design enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants