-
Notifications
You must be signed in to change notification settings - Fork 40
Sanic
Beau Barker edited this page Jul 3, 2025
·
4 revisions
Sanic server.
I beleive Sanic was completely reubilt since this example was written, so it may no longer be valid.
from sanic import Sanic
from sanic.request import Request
from sanic.response import HTTPResponse, json
from jsonrpcserver import Result, Success, dispatch_to_serializable, method
app = Sanic("JSON-RPC app")
@method
def ping() -> Result:
"""JSON-RPC method"""
return Success("pong")
@app.route("/", methods=["POST"])
async def test(request: Request) -> HTTPResponse:
"""Handle Sanic request"""
return json(dispatch_to_serializable(request.body))
if __name__ == "__main__":
app.run(port=5000)
Contributions are appreciated – simply hit Edit or New page.