samuraisam / django-json-rpc

JSON-RPC Implementation for Django
MIT License
286 stars 83 forks source link

Make JSON-RPC method registration/discovery either more explicit, or completely implicit. #49

Open ksze opened 11 years ago

ksze commented 11 years ago

Currently, we need to do this in urls.py:

from jsonrpc import jsonrpc_site
import myproj.myapp.views
urlpatterns = (
    # some url patterns ...
    url(r'^json/', jsonrpc_site.dispatch, name="jsonrpc_mountpoint"),
    # more url patterns ...
)

It is not immediately evident that the import myproj.myapp.views is actually useful. Somebody who inherits a project and needs to maintain it could erroneously believe that the import is not needed and decide to "clean it up".

I believe there are two possible ways to go:

Make it more explicit

This means having a jsonrpc_site.register function that takes these arguments:

And the method will return a set of url pattern objects that can be appended to urlpatterns.

Make it completely implicit and work by convention

This means making the discovery of json rpc methods work somewhat like django.contrib.admin, where we don't need to import the views in urls.py. Instead, have django-json-rpc scan through all the apps listed in INSTALLED_APPS of Django settings.

samuraisam commented 11 years ago

I welcome pull requests!