支持asyncio+aiohttp的REST调用。
项目描述
基于aiohttp(一个基于PEP 3156的异步http服务器)的JSON REST框架。
aiorest开发已停止
该项目一直处于实验状态:我们试图为aiohttp高级服务器提供概念证明。
现在工作已完成,最重要的部分已移植到aiohttp.web:请求和响应。
一些aiorest功能目前还不支持aiohttp.web:会话、CORS和安全。
我们正在通过为这些功能创建aiohttp扩展库来解决此问题。
我们将继续在aiohttp的新版本上维护aiorest一段时间。
请向aiorest github issue tracker报告不兼容的bug - 我们会修复这些问题。
示例用法
简单的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
更多示例请参阅示例
需求
Python 3.3
asyncio http://code.google.com/p/tulip/ 或 Python 3.4+
可选模块 aiorest.redis_session 需要 aioredis,请访问 https://github.com/aio-libs/aioredis
许可协议
aiorest 采用 MIT 许可证。
变更
0.4.0 (2015-01-18)
aiorest 库的开发已停止,请使用 aiohttp.web。
更新 aiorest 代码以兼容 aiohttp 0.14 版本。
0.3.1 (2014-12-22)
修复未处理错误的异常日志
0.3.0 (2014-12-17)
使 aiorest 与 aiohttp v0.12 兼容
0.2.5 (2014-10-30)
修复 response.write_eof() 以遵循 aiohttp 的更改
0.2.4 (2014-09-12)
使 create_session_factory() 函数中的 loop 参数为关键字参数
0.2.3 (2014-08-28)
Redis 会话从 asyncio_redis 切换到 aioredis
0.2.2 (2014-08-15)
在请求中添加了类似 Pyramid 的 matchdict(见 https://github.com/aio-libs/aiorest/pull/18)
对于 POST/PUT 方法中的错误 JSON 主体返回 "400 Bad Request" 状态码
修复了 README
自定义响应状态码(见 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
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。