vibora plus json

We’ll use Vibora to take JSON-RPC requests. It should respond to “ping” with “pong”.

Install Vibora to take requests and jsonrpcserver to process them:

$ pip install vibora jsonrpcserver

Create a server.py:

from vibora import Vibora, Request
from vibora.responses import JsonResponse
from jsonrpcserver import method, async_dispatch as dispatch

app = Vibora()

@method
async def ping():
    return "pong"

@app.route("/", methods=["POST"])
async def home(request: Request):
    request = await request.stream.read()
    response = await dispatch(request.decode())
    return JsonResponse(response.deserialized())

if __name__ == "__main__":
    app.run()

Start the server:

$ python server.py
# Vibora (0.0.7) # http://127.0.0.1:5000

Client

Use jsonrpcclient to send requests:

$ pip install "jsonrpcclient[requests]"
$ python
>>> from jsonrpcclient import request
>>> request("http://localhost:5000", "ping").data.result
'pong'