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

Correct way to provide custom RouteContext? #240

Open
krizh-p opened this issue Feb 24, 2025 · 1 comment
Open

Correct way to provide custom RouteContext? #240

krizh-p opened this issue Feb 24, 2025 · 1 comment

Comments

@krizh-p
Copy link

krizh-p commented Feb 24, 2025

I'm looking for a way to override/customize the behavior of the compute_route_parameters method in RouteContext (to transform/decode sqids into database IDs for incoming route parameters before business logic).

Currently, it seems that Ninja Extra uses a global helper function get_route_execution_context which instantiates and returns a RouteContext. I tried to replace this globally with my custom implementation but get Import Errors and it doesn't feel like the correct way to do it either.

Any guidance on how to plug in a custom sub-classed RouteContext or a feature request to allow for this customization in a clean, configurable way would be greatly appreciated. Also let me know if there's a better way to handle transforming incoming data before it hits the business logic of API routes.

Thank you!

@eadwinCode
Copy link
Owner

eadwinCode commented Feb 26, 2025

@krizh-p There is no way to extend it at the moment but I will have something in next release. The context class will be registered in NINJA_EXTRA settings.

NINJA_EXTRA = {
    "ROUTE_CONTEXT_CLASS": "ninja_extra.controllers.route.context.RouteContext"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants