Postman是chrome的插件,是google开发的一款功能强大的网页调试与发送http请求并运行测试用例的工具。后端开发的时候可以用来测试后端route的功能,在我们做前后端分离的时候,测试后台接口还是很有帮助的。
get
flask中后端有一个route的get请求,用于返回一个文件路径:
@user_bp.route('/help',methods=['GET'])
@as_json
def show_user_help():
help_path= "help.pdf"
print('help_path:',help_path)
return dict(download_help_path=help_path)
get测试代码通过的话得到:
post
用post传入json字段测试:
@project_bp.route('/business_node_copy', methods=['POST'])
@as_json
def project_restore():
#得到post传入的字段
req_data = request.get_json()
copy_list = req_data['copy_list']
pocess
之后在postman中使用post,步骤如下:
-
设置url
-
设置header中Content-Type
-
设置body
输入json格式的时候,字段引号要为双引号,不知道为什么,单引号测试不通过,改了之后没问题了.
4. send请求