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.

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.

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/resource combo 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

or the same re-written in HTTPie’s lingo

http -a "APINAME:APIKEY" POST name="orliesaurus" Age:=12 Vegan:=false https://api.arewesome.ws/v0/user.json

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.

So what are you waiting for?

pip install --upgrade httpie

or if you’re on MAC OS and want to use brew:

brew install httpie

POSTMAN and HTTPie to test APIs的更多相关文章

  1. How to Use Postman to Manage and Execute Your APIs

    How to Use Postman to Manage and Execute Your APIs Postman is convenient for executing APIs because ...

  2. SpringBoot应用的集成测试

    一.概念和定义 进行软件开发的时候,我们会写很多代码,不过,再过六个月(甚至一年以上)你知道自己的代码怎么运作么?通过测试(单元测试.集成测试.接口测试)可以保证系统的可维护性,当我们修改了某些代码时 ...

  3. Spring Boot应用的测试——Mockito

    Spring Boot应用的测试——Mockito Spring Boot可以和大部分流行的测试框架协同工作:通过Spring JUnit创建单元测试:生成测试数据初始化数据库用于测试:Spring ...

  4. Spring Boot项目中使用Mockito

    本文首发于个人网站:Spring Boot项目中使用Mockito Spring Boot可以和大部分流行的测试框架协同工作:通过Spring JUnit创建单元测试:生成测试数据初始化数据库用于测试 ...

  5. 学习python须知,Python基础进阶需掌握哪些知识点?

    Python基础进阶需要掌握哪些知识点?Python将是每个程序员的标配,有编程基础再掌握Python语言对于日后的升职加薪更有利.Python语言简洁利于理解,语法上相对容易能够让开发者更专注于业务 ...

  6. httpie 取代 curl

    接口测试有人喜欢postman(for windows or mac) 如果长期用linux工作,可能更喜欢命令的方式,比如curl最近深入了解了下django-rest-framwork,他们推荐了 ...

  7. (转载)构建public APIs与CORS

    from: https://segmentfault.com/a/1190000000709909 理由:在操作层面详细的讲解了跨域的操作.尤其是对于option请求的详解.收藏. 在构建Public ...

  8. WebAPI生成可导入到PostMan的数据

    一.前言 现在使用WebAPI来作为实现企业服务化的需求非常常见,不可否认它也是很便于使用的,基于注释可以生成对应的帮助文档(Microsoft.AspNet.WebApi.HelpPage),但是比 ...

  9. cURL和HTTPie

    http://lingxiankong.github.io/blog/2014/08/19/curl-httpie/ 前两天在网上看到一个号称比cURL更牛逼的命令行工具HTTPie,提供命令行交互方 ...

随机推荐

  1. 我常用的Mac快捷键

    1. 最小化当前窗口 command m 2. 在不同应用间切换 command tab 3. 在同一应用的不同窗口间切换 command ` 4. 在浏览器同一窗口的不同标签间切换 ctrl tab ...

  2. ServiceManager 小结

    1 ServiceManger 根据name优先从Map中获取IBinder,例如AMS.WMS.PMS:如果Map中没有对应的IBinder,我们获取Serviceanager的代理ServiceM ...

  3. iOS开发——项目实战总结&经典错误一

    经典错误一 No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=armv7, VA 运行报错 出现的原因:armv7s ...

  4. Xcode报错:“Your build settings specify a provisioning profile with the UUID..... however, no such provisioning profile was found”

    运行环境: Xcode5 & 5.0及以上版本 对工程进行Archive打包的时候出现如下错误   问题描述: Code Sign error: No matching provisionin ...

  5. Oracle存储过程执行update语句不报错不生效问题

    转载链接:http://lin49940.iteye.com/blog/466626 今天一个同事写oracle 的存储过程遇到了一个问题, 他在里面update 操作不能完成更新的操作, 但是又不会 ...

  6. 纯CSS3实现3D特效的iPhone 6动画

    iPhone 6发布不久,屌丝怎能买得起,不过作为程序员,今天看到一个用纯CSS3绘制的iPhone 6,由于CSS3特性的运用,带有点3D的动画特效,大家可以先来看看在线演示效果. 在线演示    ...

  7. 转 如何理解 重要性采样(importance sampling)

    分类: 我叫学术帖2011-03-25 13:22 3232人阅读 评论(4) 收藏 举报 图形 重要性采样是非常有意 思的一个方法.我们首先需要明确,这个方法是基于采样的,也就是基于所谓的蒙特卡洛法 ...

  8. 实现快速迭代的引擎设计 - Capcom RE Engine的架构与实现

    [译]实现快速迭代的引擎设计 - Capcom RE Engine的架构与实现 ken hu· 6 天前 原文(日文):ラピッドイテレーションを実現するゲームエンジンの設計 CEDEC2016上的一个 ...

  9. Python Django 开发 3 数据库CURD

    上一篇表建好后开始对数据进行CURD操作 dos输入: >>>python manage.py shell 以下的命令都是在shell中测试 (C)增: >>>im ...

  10. java攻城狮之路(Android篇)--ListView与ContentProvider

    一.ListView 1.三种Adapter构建ListView ListView添加条目的时候, 可以使用setAdapter(ListAdapter)方法, 常用的ListAdapter有三种 B ...