与安捷伦的iLab REST架构交互的工具。
ua-generic-rest-api的Python项目详细描述
UA通用Rest Api
为GET、PUT、POST和DELETE提供基本的restapi实现。在
动机
旨在通过创建一个通用的restapi来消除restapi实现之间的相似性,该通用restapi可以根据特定的需要扩展和重写类。在
特点
- GET—GET的实现,可以单次获取、批处理获取、带查询的单次获取,以及获取分页端点上的每个页面。
- 带有查询的批处理获取不可用,因为无法为每个get提供唯一的查询。因此,该功能不包括在内。在
- PUT—PUT的基本实现,它将有效负载放到给定的端点。在
- POST—POST的基本实现,它将有效负载发布到给定的端点。在
- DELETE-删除给定端点的基本实现。在
代码示例
fromua_generic_rest_apiimportGenericRestApiclassSpecificRestApi(GenericRestApi):# Replace '...' with any other initialization arguments.def__init__(self,...):# host, header_info, page_query, and page_tag are site specific.# Set them to your own values.super().__init__(host,header_info,page_query,page_tag=page_tag)# Can override GET, PUT, POST, or DELETE here.
- 主机-要获取的端点的基本url。在
- 头信息-要添加到请求头的任何信息,如授权或内容类型。
- 应该是字典的形式,例如{“Authorization”:None,“Content-Type”:“text/xml”}。在
- 页面查询-查询特定页面时要使用的标记。
- 例如,对于使用“”标记查询的站点?page=”,page\u查询应为“page”。在
- page_tag-获取数据时要搜索的分页端点的标记名。
- 对于用标记“page”分页的站点,page_标记应为“page”。在
安装
^{pr2}$测试
- 只有在需要对模块进行更改时,才需要进行测试。在
pip install --update node cd ./ua_generic_rest_api cd ./tests nosetests test_generic_rest_api.py
学分
许可证
麻省理工学院
- 项目
标签: