python
import json
from SimpleJSONRPCServer import SimpleJSONRPCServer
python
def add(x, y):
return x + y
def subtract(x, y):
return x - y
python
server = SimpleJSONRPCServer(('localhost', 8000))
server.register_function(add, 'add')
server.register_function(subtract, 'subtract')
python
server.serve_forever()
bash
$ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "add", "params": [3, 4], "id": 1}' http://localhost:8000
json
{"jsonrpc": "2.0", "result": 7, "id": 1}