JSON RPC protocol for aiohttp.web (http server for asyncio)
Project description
aiohttp_jrpc
jsonrpc protocol implementation for aiohttp.web.
Example
import asyncio
from aiohttp import web
from aiohttp_jrpc import Service
SCH = {
"type": "object",
"properties": {
"data": {"type": "string"},
},
}
class MyJRPC(Service):
@Service.valid(SCH)
def hello(self, ctx, data):
if data["data"] == "hello":
return {"status": "hi"}
return {"status": data}
def error(self, ctx, data):
raise Exception("Error which will catch middleware")
def no_valid(self, ctx, data):
""" Method without validation incommig data """
return {"status": "ok"}
@asyncio.coroutine
def init(loop):
app = web.Application(loop=loop, middlewares=[jrpc_errorhandler_middleware])
app.router.add_route('POST', "/api", MyJRPC)
srv = yield from loop.create_server(app.make_handler(),
"127.0.0.1", 8080)
print("Server started at http://127.0.0.1:8080")
return srv
loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
License
aiohttp_jrpc BSD license.
CHANGES
0.0.2 (2015-10-22)
Added middleware to catch exceptions
Testing internal error
0.0.1 (2015-10-18)
Init release
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiohttp_jrpc-0.0.2.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for aiohttp_jrpc-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2829880f9e0261a8c08602523a850c1eade0f1751ef422a57380bfbdd743d851 |
|
MD5 | b1c72dfd81b8b1e2f498d9cafb4952ba |
|
BLAKE2b-256 | 48d9e5d73f1ef969dc246f073477dd09a095f2b55c20650b1293c264a1098100 |