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

Middleware functions #126

Open
deptyped opened this issue Jul 8, 2020 · 2 comments
Open

Middleware functions #126

deptyped opened this issue Jul 8, 2020 · 2 comments

Comments

@deptyped
Copy link
Contributor

deptyped commented Jul 8, 2020

from jsonrpcserver.methods import Methods

# During initialization, Methods class receives a list of decorators
admin_methods = Methods(decorators=[require_user, require_role('admin')])

# When adding a new method, the function will be wrapped by decorators from the list
@admin_methods.add
# @require_user
# @require_role('admin')
def admin_ping():
    return "pong"


user_methods = Methods(decorators=[require_user])

@user_methods.add
# @require_user
def user_ping():
    return "pong"


methods = Methods()
methods.extend(admin_methods)
methods.extend(user_methods)

What do you think of this idea @bcb? I want to implement this

@bcb
Copy link
Member

bcb commented Jul 10, 2020

Great idea @deptyped , go for it!

@bcb
Copy link
Member

bcb commented Jul 12, 2020

Just an idea - perhaps some parts of this library, such as the schema validation, could be moved into middleware layers, to give the user more control over which parts are used.

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