这里是包装说明。
nr.databind.rest的Python项目详细描述
Note: This package is in the dangerous land of
0.x.y
versions and may be subject to breaking changes with minor version increments.
This package is superseded by astra.http.
在nr.databind.rest在
这个模块可以用来定义一个使用python3的restapi接口
注释和nr.databind
对象映射功能。在
Todo
- []为REST客户机生成动态和静态代码
示例
资源是通过定义Interface
子类并装饰其
方法使用@Route
修饰符。然后子类可以用于
自动生成客户端代码并基于
相同的接口。在
frommy.service.api.typesimportMyRequest,MyResponsefromnr.databind.restimportRoute,RouteParamfromnr.interfaceimportInterfaceclassMyResource(Interface):@Route('GET /my-endpoint/{parameter_a}')defmy_get_endpoint(self,parameter_a:str,parameter_b:RouteParam.Query(int))->MyResponse:...@Route('POST /my-endpoint/{parameter_a}')defmy_post_endpoint(self,parameter_a:str,body:MyRequest)->MyResponse:...
然后按如下方式实现资源:
^{pr2}$然后可以使用 绑定机制(目前只有烧瓶可用)。在
fromflaskimportFlaskfrommy.service.api.resources_implimportMyResourceImplfromnr.databind.restimportMimeTypeMapperfromnr.databind.rest.flaskimportbind_resourceapp=Flask(__name__)mapper=MimeTypeMapper.json()bind_resource(app,'/my-resource',MyResourceImpl(),mapper=mapper)
- 项目
标签: