JSON-RPC implementation for Starlette framework
Project description
starlette-jsonrpc
Installation
pip install 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 params["x"] - params["y"]
@dispatcher.add_method(name="SubtractMethod")
async def seconds_subtract(params):
return params["x"] - params["y"]
@dispatcher.add_method
async def subtract_positional(x, y):
return 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": 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 ;)
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
File details
Details for the file starlette-jsonrpc-0.2.0.tar.gz
.
File metadata
- Download URL: starlette-jsonrpc-0.2.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 800d517a3b0a89500793f2999b690c59fcd7134dfedf488bebc03f356bc09c15 |
|
MD5 | b6e6bb1e11d8a2cefa047fa4a6d561ec |
|
BLAKE2b-256 | fe5ec1b4c28505701e918dce71f18f846bb93f96e6f21f751e4e01ff5bc55216 |
File details
Details for the file starlette_jsonrpc-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: starlette_jsonrpc-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcc34787df48f0e01d35a9de1267a5f7468bda0045393e1f5260c784c48864a5 |
|
MD5 | a3b9188b1491e0e5c18f5843859645b3 |
|
BLAKE2b-256 | beda724e9c98f7410b070b091e4bbc2429d8b22e7813699568bdd171547bb403 |