jsonrpcserver icon indicating copy to clipboard operation
jsonrpcserver copied to clipboard

Middleware functions

Open deptyped opened this issue 3 years ago • 2 comments

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

deptyped avatar Jul 08 '20 12:07 deptyped

Great idea @deptyped , go for it!

bcb avatar Jul 10 '20 02:07 bcb

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.

bcb avatar Jul 12 '20 00:07 bcb