全栈工程师修炼iOS菜鸟级开发项目开发技巧

API开发神器-Postman

2016-06-13  本文已影响17372人  Yuan_Jie

Postman helps you develop APIs faster.

豪华午餐

Postman

Postman

构建、管理、文档化API

Newman(我真的不是MP3)

Newman

Newman is a command-line collection runner forPostman. It allows you to effortlessly run and test a Postman collection directly from the command-line. It is built with extensibility in mind so that you can easily integrate it with your continuous integration servers and build systems.

➜  Downloads newman -c Demo.postman_collection.json

Iteration 1 of 1
200 1479ms Open the url of Baidu. [GET] http://www.baidu.com
    ✔ Status code is 200

Summary:

Parent                      Pass Count   FailCount
-------------------------------------------------------------
Collection Demo                      1           0

Total                                1           0
➜  ~ newman -u https://www.getpostman.com/collections/676a42223e14bf54ad84

Iteration 1 of 1
200 240ms Open the url of Baidu. [GET] http://www.baidu.com
    ✔ Status code is 200

Summary:

Parent                      Pass Count   FailCount
-------------------------------------------------------------
Collection Demo                      1           0

Total                                1           0
Interceptor

Interceptor

Postman interceptor brings the power of your Chrome window to Postman! You can set custom headers (including cookies) from within Postman, and view cookies already set on the domain. You can also capture requests being sent from Chrome and import them into Postman. This makes building APIs a breeze!

初级使用

录制API-Interceptor

回放API-Postman

指定API请求-Postman

高级使用

�规划管理API-Postman+Collection

将所有的API进行分类管理,如按模块、系统、类型

保存API至Collection

重命令API请求-便于管理和查看

常用权限应用尽有-Authorization

Authorization设置 Basic Auth

完全自定义的头-header

Header设置

完美的数据体-body

Body设置

请求前还能做点事-Pre-request Script

Pre-request Script设置

验证API请求结果-Tests

Postman提供了常用的测试功能:返回内容处理、状态码判断、请求超时等。点击后自动添加到Test脚本中

Test命令集合

进阶使用

带你快速走向各个环境-Environment

使用Evnironment,可设置环境地址及环境中的不同数据,便于在跨环境后, 相同API可快速使用,减少调整API的成本

分享你的成果-导出/导入 or share

导出-Download

导入-Import

分享-share

导出/导入、share,便于在团队内部协作时使用,API的请求及管理团队化

�海量执行你的请求-Runner

当你有大量的API时,肯定想一次执行多个多次执行多个,Postman的Runner可以满足你的需求。

�CI挂起来-Newman

直接使用Newman命令,快速把Postman与CI集成起来(直接使用shell命令,即可)。

newman -c demo.postman_collection --exitCode 1

PS:

参考

上一篇 下一篇

猜你喜欢

热点阅读