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