Changes between Initial Version and Version 1 of Django-JSON-RPC


Ignore:
Timestamp:
Mar 21, 2011, 12:59:20 AM (14 years ago)
Author:
anaoum
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Django-JSON-RPC

    v1 v1  
     1
     2== Django JSON-RPC ==
     3
     4A basic JSON-RPC Implementation for Django powered sites (see https://github.com/anaoum/django-json-rpc).
     5
     6
     7=== Features: ===
     8
     9Simple, pythonic API
     10Supports JSON-RPC 2.0 Spec
     11
     12=== The basic API: ===
     13
     14''project/app/views.py''
     15
     16{{{
     17from pe.jsonrpc.views import JsonRpcView
     18from pe.jsonrpc.decorators import publicmethod
     19
     20class TestRpcMethods(object):
     21    namespace = "test"
     22    @publicmethod
     23    def hello(self, who="World"):
     24        return "Hello, %s!" % who
     25    @publicmethod
     26    def echo(self, value):
     27        return value
     28
     29rpc = JsonRpcView.as_view(classes=[TestRpcMethods])
     30}}}
     31
     32''project/urls.py''
     33
     34{{{
     35from django.conf.urls.defaults import *
     36
     37urlpatterns = patterns('',
     38    (r'^rpc/json/$', 'app.views.rpc'),
     39)
     40}}}
     41
     42To test your service: You can test the service with jsonrpclib (https://github.com/joshmarshall/jsonrpclib) or similar:
     43
     44{{{
     45
     46>>> from jsonrpclib import Server
     47
     48>>> s = Server('http://localhost:8000/rpc/json/')
     49
     50>>> s.test.hello()
     51u'Hello, World!'
     52
     53>>> s.test.hello('Andrew')
     54u'Hello, Andrew!'
     55
     56>>> s.test.hello(who='Bob')
     57u'Hello, Bob!'
     58
     59>>> s.test.echo('This is a test...')
     60u'This is a test...'
     61}}}
Back to Top