支持asyncio+aiohttp的rest调用。
aiorest的Python项目详细描述
基于aiohttp(一个异步(PEP 3156)http服务器)的JSON REST框架
雨林开发已经停止
这个项目一直处于试验阶段:我们试图证明 aiohttp高级服务器的概念。
现在工作完成了,最重要的部分移植到 aiohttp.web:Request和Response。
aiohttp.web尚不支持某些aiorest功能: 会话、cors和安全。
我们正在通过对aiohttp进行扩展来努力解决这个问题 那些图书馆。
我们将保持aiorest在aiohttp的新版本上工作 同时。
请向aiorest github报告不兼容错误 问题跟踪器-我们会解决的。
示例用法
简单的rest服务器可以这样运行:
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()
这将打印{'hello': 'world'}json
有关详细信息,请参见examples。
要求
- Python3.3
- 异步http://code.google.com/p/tulip/或python 3.4+
- aiohttphttp://github.com/KeepSafe/aiohttp
- 可选模块aiorest.redis_session需要aioredis https://github.com/aio-libs/aioredis
许可证
aiorest是根据麻省理工学院的许可证提供的。
更改
0.4.0(2015-01-18)
- aiorest库的开发已经停止,改用aiohttp.web。
- 更新aiorest代码以与aiohttp 0.14 release兼容
0.3.1(2014-12-22)
- 修复了未处理错误的异常日志记录
0.3.0(2014-12-17)
- 使aiorest与aiohttp v0.12兼容
0.2.5(2014-10-30)
- 修复响应。编写eof()以跟踪aiohttp更改
0.2.4(2014-09-12)
- 函数create_session_factory()中的make loop keywork only参数
0.2.3(2014-08-28)
- redis会话从asyncio_redis切换到aioredis
0.2.2(2014-08-15)
- 添加了类似金字塔的matchdict以请求 (见https://github.com/aio-libs/aiorest/pull/18)
- 对于post/put方法中不正确的json正文,返回“400错误请求”
- 已修复自述文件
- 自定义响应状态代码 (见https://github.com/aio-libs/aiorest/pull/23)
0.1.1(2014-07-09)
- 切换到aiohttp v0.9.0
0.1.0(2014-07-07)
- 基本rest api