Skip to content

Instantly share code, notes, and snippets.

@wwj718
Last active September 6, 2018 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wwj718/b2e417ee1fc9c805bfa47febf1a0bda4 to your computer and use it in GitHub Desktop.
Save wwj718/b2e417ee1fc9c805bfa47febf1a0bda4 to your computer and use it in GitHub Desktop.
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