Browse code
Edited README.markdown via GitHub
fiddlerwoaroof authored on 31/05/2011 17:30:52
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -1,18 +1,48 @@ |
1 | 1 |
A JSON-RPC 2.0 implementation for Python (Python 3 not supported yet) |
2 | 2 |
|
3 | 3 |
|
4 |
-You can get started with: |
|
4 |
+## Getting Started |
|
5 | 5 |
|
6 |
-Python 2.7: `python -m jsonrpc <host name>` |
|
6 |
+- Start the Server: |
|
7 | 7 |
|
8 |
-Python 2.6: `python -m jsonrpc.__main__ <host name>` |
|
8 |
+ % python -m jsonrpc.example_server |
|
9 |
+ Listening on port 8007... |
|
10 |
+ |
|
11 |
+- Start the Client: |
|
12 |
+ - Python 2.7: `python -m jsonrpc <host name>` |
|
13 |
+ - Python 2.6: `python -m jsonrpc.__main__ <host name>` |
|
9 | 14 |
|
10 | 15 |
|
11 | 16 |
>>> server.add(1, 2) |
12 | 17 |
3 |
18 |
+ |
|
13 | 19 |
>>> server.subtract(3,2) |
14 | 20 |
1 |
15 | 21 |
|
22 |
+ # Exceptions |
|
23 |
+ >>> server.add(1, '2') |
|
24 |
+ Traceback (most recent call last): |
|
25 |
+ File "<stdin>", line 1, in <module> |
|
26 |
+ File "jsonrpc/proxy.py", line 182, in __call__ |
|
27 |
+ raise JSONRPCException(resp['error']) |
|
28 |
+ jsonrpc.proxy.JSONRPCException: unsupported operand type(s) for +: 'int' and 'unicode' |
|
29 |
+ |
|
30 |
+ |
|
31 |
+ >>> server.batch_call( dict(add=( (1,2), {} ), subtract=( (3,2), {} )) ) |
|
32 |
+ [(3, None), (1, None)] # the pattern is (result, error) |
|
33 |
+ |
|
34 |
+ # batch calls can also be done with an iterable, if you want |
|
35 |
+ # to have more than one call to the same method |
|
36 |
+ >>> server.batch_call( [('add', ((1, 2), {})), ('subtract', ((3, 2), {}))] ) |
|
37 |
+ [(3, None), (1, None)] |
|
38 |
+ |
|
39 |
+ # Exceptions in batch calls |
|
40 |
+ >>> server.batch_call( dict(add=( (1,2), {} ), subtract=( (3,'2'), {} )) ) |
|
41 |
+ [(3, None), (None, {u'message': u"unsupported operand type(s) for -: 'int' |
|
42 |
+ and 'unicode'", u'code': 0, u'data': [u"unsupported operand type(s) for -: |
|
43 |
+ 'int' and 'unicode'"]})] |
|
44 |
+ |
|
45 |
+ |
|
16 | 46 |
|
17 | 47 |
Made for: |
18 | 48 |
http://ncmi.bcm.edu |
19 | 49 |
\ No newline at end of file |