Support REST calls for asyncio+aiohttp.
Project description
JSON REST framework based on aiohttp (an asyncio (PEP 3156) http server).
Example usage
Simple REST server can be run like this:
import asyncio import aiohttp import aiorest # define a simple request handler # which accept no arguments # and responds with json def hello(request): return {'hello': 'world'} loop = asyncio.get_event_loop() server = aiorest.RESTServer(hostname='127.0.0.1', loop=loop) # configure routes server.add_url('GET', '/hello', hello) # create server srv = loop.run_until_complete(loop.create_server( server.make_handler, '127.0.0.1', 8080)) @asyncio.coroutine def query(): resp = yield from aiohttp.request( 'GET', 'http://127.0.0.1:8080/hello', loop=loop) data = yield from resp.read_and_close(decode=True) print(data) loop.run_until_complete(query()) srv.close() loop.run_until_complete(srv.wait_closed()) loop.close()
this will print {'hello': 'world'} json
See examples for more.
Requirements
Python 3.3
asyncio http://code.google.com/p/tulip/ or Python 3.4+
optional module aiorest.redis_session requires aioredis https://github.com/aio-libs/aioredis
License
aiorest is offered under the MIT license.
CHANGES
0.2.5 (2014-10-30)
Fix response.write_eof() to follow aiohttp changes
0.2.4 (2014-09-12)
Make loop keywork-only parameter in create_session_factory() function
0.2.3 (2014-08-28)
Redis session switched from asyncio_redis to aioredis
0.2.2 (2014-08-15)
Added Pyramid-like matchdict to request (see https://github.com/aio-libs/aiorest/pull/18)
Return “400 Bad Request” for incorrect JSON body in POST/PUT methods
README fixed
Custom response status code (see https://github.com/aio-libs/aiorest/pull/23)
0.1.1 (2014-07-09)
Switched to aiohttp v0.9.0
0.1.0 (2014-07-07)
Basic REST API
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.