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.aio import methods

app = Vibora()

@methods.add
async def ping():
    return 'pong'

@app.route('/', methods=['POST'])
async def home(request: Request):
    response = await methods.dispatch(await request.json())
    return JsonResponse(response)

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.clients.http_client import HTTPClient
>>> HTTPClient("http://localhost:5000").request("ping").data.result
'pong'