Atsushi Odagiri avatar Atsushi Odagiri committed 7320ae2

write a document.

Comments (0)

Files changed (3)

 develop =
     src/jsonrpc
     src/wsgitestapp
+find-links =
+    http://pypi.python.org/pypi/docutils
 
 [eggs]
 recipe = zc.recipe.egg
     jsonrpc
     nose
     WebTest
+    docutils
+    sphinx

src/jsonrpc/docs/conf.py

+# config for sphinx
+master_doc = 'index'
+source_encoding = 'utf-8'
+project = u'jsonrpc'
+copyright = u'2010, Atsushi Odagiri'

src/jsonrpc/docs/index.rst

+================
+JSON RPC
+================
+jsonrpcは、JSON RPCによる呼び出しを可能にするWSGIアプリケーションです。
+`JSON RPC Spec2 Draft <http://groups.google.com/group/json-rpc/web/json-rpc-1-2-proposal>`_
+に準拠させるようにしています。
+JSONパーサーは、json, django.utils.simplejson, simplejsonを順に検索して最初に見つかったものを利用します。
+
+基本的な使い方
+==================================================================
+
+>>> from webtest import TestApp
+>>> import jsonrpc
+
+addメソッドで、RPCメソッドを追加します。
+
+>>> app = jsonrpc.JsonRpcApplication()
+>>> app.add('hello', lambda n: "Hello, %s!" % n)
+>>> app = TestApp(app)
+>>> res = app.post('/', '{"jsonrpc":"2.0", "method":"hello", "params":["aodag"], "id":"x"}', extra_environ={'CONTENT_TYPE':'application/json'})
+>>> res.status_int
+200
+>>> res.json['id']
+'x'
+>>> res.json["result"]
+'Hello, aodag!'
+
+
+モジュール単位で追加可能です。
+tests.sample.py::
+
+  def greeting(n):
+      return "Hello, %s" % n
+
+
+>>> import tests.sample
+>>> app = jsonrpc.JsonRpcApplication()
+>>> app.addModule(tests.sample)
+>>> app = TestApp(app)
+>>> res = app.post('/', '{"jsonrpc":"2.0", "method":"tests.sample.greeting", "params":["aodag"], "id":"y"}', extra_environ={'CONTENT_TYPE':'application/json'})
+>>> res.status_int
+200
+>>> res.json['id']
+'y'
+>>> res.json["result"]
+'Hello, aodag'
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.