JSON-RPC implementation for Starlette framework
Project description
starlette-jsonrpc
Examples
Code:
import uvicorn
from starlette.applications import Starlette
from starlette_jsonrpc import dispatcher
from starlette_jsonrpc.endpoint import JSONRPCEndpoint
app = Starlette()
@dispatcher.add_method
async def subtract(params):
return {"result": params["x"] - params["y"]}
@dispatcher.add_method(name="SubtractMethod")
async def seconds_subtract(params):
return {"result": params["x"] - params["y"]}
@dispatcher.add_method
async def subtract_positional(x, y):
return {"result": x - y}
app.mount("/api", JSONRPCEndpoint)
if __name__ == "__main__":
uvicorn.run(app)
Example of requests:
{
"jsonrpc": "2.0",
"method": "subtract",
"params": {"x": 42, "y": 23},
"id": "1"
}
{
"jsonrpc": "2.0",
"method": "SubtractMethod",
"params": {"x": 42, "y": 23},
"id": "1"
}
{
"jsonrpc": "2.0",
"method": "subtract_positional",
"params": [42, 23],
"id": "1"
}
Example of response:
{
"jsonrpc": "2.0",
"id": "1",
"result": {"result": 19}
}
Contributing
Thank you for your interest in contributing. Everyone is welcome to take part in developting this package. Please fFollow contributing guide in CONTRIBUTING.md.
Support
If you like this project and find it useful and want to say "Thank you", please consider to buy me a coffee ;)
todo:
- add namespaces
- add guide how to install package
- push package to pypi repository
- add type annotations
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for starlette_jsonrpc-0.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b9b23a0a1c08726f870ce2ba89c9d7a756d251e1bc85866b4c39a92a477a24a |
|
MD5 | da66184f24421ca439a03fe27c9aa91a |
|
BLAKE2b-256 | d7930d4711588ec4c5932028eb1edd2f9d08c43a3fa4c80d5bd268990d5757c8 |