Skip to main content

JSON RPC protocol for aiohttp.web (http server for asyncio)

Project description

aiohttp_jrpc

https://travis-ci.org/zloidemon/aiohttp_jrpc.svg?branch=master https://coveralls.io/repos/zloidemon/aiohttp_jrpc/badge.svg

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)

Uploaded Source

Built Distribution

aiohttp_jrpc-0.0.2-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page