aiohttp的快速休息资源
aiorestapi的Python项目详细描述
aiohttp的快速休息资源
主要特点
- 同时支持HTTP协议的客户端和服务器端。在
入门
aiorestapi
允许您通过几个步骤快速创建rest资源。它自动在集合或单个项上创建资源路由;只需在方法上指定后缀''u collection'或''u item'。
结果/请求的序列化/反序列化使用python字典透明地进行。在
创建简单rest资源的示例
fromaiohttpimportwebfromaiorestapiimportRestView,routes@routes.resource("/views")classRestResource(RestView):# example call: GET to <server>/views?start=10asyncdefon_get_collection(self,start=0)->list:return[{"id":int(start)+1,"value":1},{"id":int(start)+2,"value":2},]# example call: GET <server>/views/80asyncdefon_get_item(self,id:str)->dict:returnself.key# example call: POST to <server>/viewsasyncdefon_post_collection(self,body:dict)->dict:returnbodyapp=web.Application()app.add_routes(routes)app['key']=[1,2,4,5]if__name__=='__main__':web.run_app(app)
安装
安装aiorestapi非常简单:
^{pr2}$注释
- @在routes.资源decorator装饰器自动将路由添加到“/myresources”和“/myresources/{id}”
- 从RestView对象,可以使用自我请求在
- 查询参数将自动转换为视图方法的参数。在
- 如果请求有一个主体,则有必要在方法中指定一个名为“body”的参数
- 如果请求针对单个项,则需要指定一个名为“id”的参数
- 存储为“app[]”的项可以作为属性“self”访问视图
待办事项
- 测试!!在
- 文件
- 可配置的自定义序列化程序/反序列化程序
要求
- Python>;=3.6
- aiohttp
许可证
aiorestapi
是在Apache2许可证下提供的。在
源代码
GitHub存储库中提供了最新的开发人员版本: https://github.com/aiselis/aiorestapi
- 项目
标签: