JSON-RPC server based on fastapi
Project description
Description
JSON-RPC server based on fastapi:
Installation
pip install fastapi-jsonrpc
Usage
pip install uvicorn
import fastapi_jsonrpc as jsonrpc
from fastapi_jsonrpc import Param
from pydantic import BaseModel
app = jsonrpc.API()
api_v1 = jsonrpc.Entrypoint('/api/v1/jsonrpc')
class MyError(jsonrpc.BaseError):
CODE = 5000
MESSAGE = 'My error'
class DataModel(BaseModel):
details: str
@api_v1.method(errors=[MyError])
def echo(
data: str = Param(..., example='123'),
) -> str:
if data == 'error':
raise MyError(data={'details': 'error'})
else:
return data
app.bind_entrypoint(api_v1)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, port=5000, debug=True, access_log=False)
Go to:
Development
Install poetry
Install dependencies
poetry update
Install dephell
pip install dephell
Regenerate setup.py
dephell deps convert
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
fastapi-jsonrpc-0.1.16.tar.gz
(8.1 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_jsonrpc-0.1.16-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e01e52334d1a9337780ec78b4813d3b41f615c9d4c8b3ffc6d6e8dd7af2c3795 |
|
MD5 | df902cb3f9e02ff097eeda571d4a8f8b |
|
BLAKE2b-256 | 352055806b679565bbacfc291a94fe5b065d49e3fa43e5c4cec224ed32ebb398 |