POSTMAN and HTTPie to test APIs
2016-05-27 02:26
471 查看
http://blog.mashape.com/postman-httpie-test-apis/
We love working with APIs at Mashape, and we love sharing with our community new tools that make your life easier when consuming APIs.
Today, we’re taking a look at POSTMAN (Free edition), a GUI powered API client and HTTPie a powerful CLI replacement (or addition) for cURL.
![](http://i0.wp.com/blog.mashape.com/wp-content/uploads/2014/12/postman.png?resize=600%2C290)
Fig 1. This is what POSTMAN looks like at first glance
Personally I find that POSTMAN has a very clean and simple interface that allows anyone to consume APIs in matter of seconds. After the installation, you can run this tool as a web-packaged app running independently of your Chrome browser. This means you still need Chrome to be installed somewhere on your machine.
In terms of features, POSTMAN has the ability to quickly run API queries and have a back-log (called History in POSTMAN) that allows anyone to replay a certain query, or multiple. This is a great way when you’re testing an API and want to play with different values without having to copy-paste the request over and over, while maintaining (using the option) every single output response from the server.
Quickly Abstract your API documentation
A clear documentation is often the key to a good API. After all, it is vital that a developer is able to understand your product and consume your API easily. So why not prepare a bunch of API requests with pre-filled data for him to test different aspects?
At Mashape we allow you to document your API, and insert default values to kickstart the API development and consumption process. On top of that, we allow you to give meaningful response models to each call. This way when someone runs a query against an endpoint, there will be no surprises! A good way to understand how to structure your documentation is to have a bunch of endpoints with pre-filled values hosted somewhere. And this is where POSTMAN comes in handy, you can arrange API calls in folders called Collections.
POSTMAN allows you to collect a bunch of endpoints into a collection for later use. This is a great way to get ready to deploy your documentation on Mashape as it gives you an idea of which endpoints, parameters and models you’ll be using when documenting your API.
Multiple Auth Support
Nearly all APIs require a form of authentication.
Basic Authentication – The typical
Query Authentication – Using a parameter passed with each request to authorise it such as:
OAuth 1a and 2 Authentication – The typical Oauth authentication flow
API Testing (PAID plan)
With the paid plan, you can use simple Javascript code snippets to test your API responses. Some of the tests you can run in POSTMAN are checking response times, status codes and validating server responses. The Test suite allows to cut down on development lines of code written by developers to test APIs, but it comes with a small cost as this feature is actually only available to paid users at $9.99$ for a lifetime license.
cURL vs HTTPie
So what are you waiting for?
or if you’re on MAC OS and want to use brew:
We love working with APIs at Mashape, and we love sharing with our community new tools that make your life easier when consuming APIs.
Today, we’re taking a look at POSTMAN (Free edition), a GUI powered API client and HTTPie a powerful CLI replacement (or addition) for cURL.
1. POSTMAN
POSTMAN is a compelling HTTP client for APIs built by Abhinav Asthana. With POSTMAN you can consume APIs in a straightforward way, solving the complexity of complex HTTP query and parsing. You can download POSTMAN here: http://www.getpostman.com/. As the website states, this tool has been the highest rated productivity app on the Chrome Web Store with more than 500,000 downloads.![](http://i0.wp.com/blog.mashape.com/wp-content/uploads/2014/12/postman.png?resize=600%2C290)
Fig 1. This is what POSTMAN looks like at first glance
Personally I find that POSTMAN has a very clean and simple interface that allows anyone to consume APIs in matter of seconds. After the installation, you can run this tool as a web-packaged app running independently of your Chrome browser. This means you still need Chrome to be installed somewhere on your machine.
In terms of features, POSTMAN has the ability to quickly run API queries and have a back-log (called History in POSTMAN) that allows anyone to replay a certain query, or multiple. This is a great way when you’re testing an API and want to play with different values without having to copy-paste the request over and over, while maintaining (using the option) every single output response from the server.
Quickly Abstract your API documentation
A clear documentation is often the key to a good API. After all, it is vital that a developer is able to understand your product and consume your API easily. So why not prepare a bunch of API requests with pre-filled data for him to test different aspects?
At Mashape we allow you to document your API, and insert default values to kickstart the API development and consumption process. On top of that, we allow you to give meaningful response models to each call. This way when someone runs a query against an endpoint, there will be no surprises! A good way to understand how to structure your documentation is to have a bunch of endpoints with pre-filled values hosted somewhere. And this is where POSTMAN comes in handy, you can arrange API calls in folders called Collections.
POSTMAN allows you to collect a bunch of endpoints into a collection for later use. This is a great way to get ready to deploy your documentation on Mashape as it gives you an idea of which endpoints, parameters and models you’ll be using when documenting your API.
Multiple Auth Support
Nearly all APIs require a form of authentication.
Basic Authentication – The typical
https://apikey:secretkey@api.site.com/resourcecombo to authenticate a request
Query Authentication – Using a parameter passed with each request to authorise it such as:
https://api.site.com/?token=123abc
OAuth 1a and 2 Authentication – The typical Oauth authentication flow
API Testing (PAID plan)
With the paid plan, you can use simple Javascript code snippets to test your API responses. Some of the tests you can run in POSTMAN are checking response times, status codes and validating server responses. The Test suite allows to cut down on development lines of code written by developers to test APIs, but it comes with a small cost as this feature is actually only available to paid users at $9.99$ for a lifetime license.
2. HTTPie
If you work with APIs, you most probably have used cURL at least a couple of times in your life. cURL is extremely powerful, but a pain in the back to use when dealing with a lot of API calls written manually. HTTPie sets itself as a solution to the verbosity and “complexity” of cURL commands. In my opinion it’s great and if you’ve not been using HTTPie in your workflow you’re missing out!cURL vs HTTPie
curl -u "APINAME:APIKEY" -X POST -d '{"name": "orliesaurus", "Age": 12, "Vegan": false}' -H "Content-type: application/json" https://api.arewesome.ws/v0/user.json[/code]
or the same re-written in HTTPie’s lingohttp -a "APINAME:APIKEY" POST name="orliesaurus" Age:=12 Vegan:=false https://api.arewesome.ws/v0/user.json[/code] Way better right?
These are the things you need to remember when using HTTPie, pretty much, the rest comes au naturel!
Item Type | Description |
---|---|
HTTP Headers Name:Value | Arbitrary HTTP header, e.g. X-API-Token:123. |
URL parameters name == value | Appends the given name/value pair as a query string parameter to the URL. The == separator is used. |
Data Fields field=value,field=@file.txt | Request data fields to be serialized as a JSON object (default), or to be form-encoded (–form, -f). |
Raw JSON fields field:=json,field:=@file.json | Useful when sending JSON and one or more fields need to be a Boolean,Number, nested Object, or an Array, e.g., meals:='[“ham”,”spam”]’ or pies:=[1,2,3] (note the quotes). |
Form File Fields field@/dir/file | Only available with –form, -f. For example: screenshot@~/Pictures/img.png. The presence of a file field results in a multipart/form-data request. |
pip install --upgrade httpie
or if you’re on MAC OS and want to use brew:
brew install httpie
相关文章推荐
- 使用AVPlayer播放网络歌曲
- 计算机网络——网络层
- JSON 提交http数据
- 网络异常分析CFURLConnectionSendSynchronousRequest
- Python 即时网络爬虫项目: 内容提取器的定义
- 网络安全概述之基本攻击方式介绍思维导图(Xmind)
- Cisco Packet Tracer 5 汉化版 | 学习网络配置的学习工具
- 网络游戏实现UDP通信
- socket网络通信学习(一)
- MACOSX 网络诊断命令
- 检查当前手机网络的Android代码
- Android网络:HTTP之利用HttpURLConnection访问网页、获取网络图片实例 (附源码)
- 菜鸟网络
- java 安全通信: HTTPS与SSL
- 使用 okhttp 与 sae 进行数据交互
- TCP的长连接与短连接
- TCP协议三次握手和四次挥手
- 走近HTTP协议之一 基本网络概念与理解
- python网络爬虫学习(四)正则表达式的使用之re的其他方法
- HttpClient 教程 (一)