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(): 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 asyncio_redis https://github.com/jonathanslenders/asyncio-redis
License
aiorest is offered under the MIT license.
CHANGES
0.1.0 (XXXX-XX-XX)
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.
Source Distribution
aiorest-0.0.3.tar.gz
(12.3 kB
view details)
Built Distribution
aiorest-0.0.3-py3-none-any.whl
(16.7 kB
view details)
File details
Details for the file aiorest-0.0.3.tar.gz
.
File metadata
- Download URL: aiorest-0.0.3.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a685fc1b9ed0fa152aa602e2326fd0016335f44968d3a9a8eb6eb266259e51ee |
|
MD5 | c61d174d87e92ad0207ba913ed7562f3 |
|
BLAKE2b-256 | 12f1700d621a62502607bb05565622dcecdba2939eef4395954940a60059ed81 |
Provenance
File details
Details for the file aiorest-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: aiorest-0.0.3-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5340e04be5a7dee3ba4db65aa3bf313cb50ceb19ced8fe22314af7c7760a1c59 |
|
MD5 | 632d10b4b9a251ad537fe32a455286e8 |
|
BLAKE2b-256 | c05e122b4effedc5c76ea16807bdc5ce093b459503eba4d63a5ef16e256decc2 |