Last active
September 6, 2018 10:25
-
-
Save wwj718/b2e417ee1fc9c805bfa47febf1a0bda4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jsonrpc import JSONRPCResponseManager, dispatcher | |
dispatcher["echo"] = lambda s: s | |
dispatcher["add"] = lambda a, b: a + b | |
import json | |
request_data = { | |
"method": "echo", | |
"params": ["echome!"], | |
"jsonrpc": "2.0", | |
"id": 0, | |
} | |
response = JSONRPCResponseManager.handle(json.dumps(request_data), dispatcher) | |
response.json | |
# '{"result": "echome!", "id": 0, "jsonrpc": "2.0"}' | |
# test Method not found | |
request_data = { | |
"method": "echo_test", | |
"params": ["echome!"], | |
"jsonrpc": "2.0", | |
"id": 0, | |
} | |
response = JSONRPCResponseManager.handle(json.dumps(request_data), dispatcher) | |
response.json | |
# '{"error": {"code": -32601, "message": "Method not found"}, "id": 0, "jsonrpc": "2.0"}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment