-
-
Notifications
You must be signed in to change notification settings - Fork 103
misc updates #95
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
base: master
Are you sure you want to change the base?
misc updates #95
Conversation
- Support custom json encoder for serializing response data - Support registering global decorators for jsonrpc methods - Support custom method prefix for Dispatcher.add_class - Support explicitly exporting subset of class methods with Dispatcher.add_class
Below is the code to reveal this bug: @dispatcher.add_class class ProcessOrderAPI(APISet): rpc_exports = ['query', 'detail', 'start', 'update'] rpc_method_prefix = 'ProcessOrder' Model = ProcessOrder def update(self, object, attrs): # NOTE HERE: Since add_class retuns None previously, # So the 1st argument of super() is None return super(ProcessOrderAPI, self).update(object, attrs)
Hi, @wonderbeyond Thank you for the PR and sorry for coming back late. After closer inspection of your code, I've noticed that there are quite many features there. Some of them I completely support, others - not. Using custom json serializer is convenient, I'm on the same page. Three other features I'd like to discuss:
@dispatcher.add_method
@login_required
def my_handler():
pass
@dispatcher.add_method(prefix='Cell')
def my_method():
pass There is no support for prefix in case of class yet but this would be a proper place for prefix handler: @dispatcher.add_class(prefix='Cell')
class CellAPI:
pass
|
One more thing: dispatcher should not know about any hooks. They could be implemented in manager. |
However I want a way for global decorator for all rpc handlers.
I see no
Yes, I think your style is better.
In my practice, I define a base class naming This class acts as a template, provides common CURD methods, which a subclass has no need to override in general. Give the the right For security considerations, I only export |
I've tried, but I found Code sample from README: @Request.application
def application(request):
# Dispatcher is dictionary {<method_name>: callable}
dispatcher["echo"] = lambda s: s
dispatcher["add"] = lambda a, b: a + b
response = JSONRPCResponseManager.handle(
request.data, dispatcher)
return Response(response.json, mimetype='application/json') I found no elegant way to bind extra data to the manager. Can we make some change? |
Some misc updates when I apply json-rpc to latest two projects. Just for your review.
Dispatcher.add_method
as a decorator generatorSome use cases from my real projects