POSTMAN and HTTPie to test APIs

Source: Internet
Author: User
Tags oauth

http://blog.mashape.com/postman-httpie-test-apis/

We love working with APIs at Mashape, and we love sharing with our community new tools, the make your life easier when con Suming APIs.

Today, we ' re taking a look at POSTMAN (Free edition), a GUI powered API client and HTTPie a powerful CLI replacement (or a ddition) 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, solving the complexity of complex HTTP query and parsing. You can download POSTMAN here:http://www.getpostman.com/. As the website states, this tool have been the highest rated productivity app on the Chrome Web Store with more than 500,00 0 downloads.

Fig 1. POSTMAN looks like at first glance

Personally I find that POSTMAN have a very clean and simple interface The allows anyone to consume APIs in matter of Secon Ds. After the installation, you can run this tool as a web-packaged app running independently of your Chrome browser. This means your still need Chrome to be installed somewhere on your machine.

In terms of features, POSTMAN had the ability to quickly run API queries and had a back-log (called history in POSTMAN) T Hat allows anyone to replay a certain query, or multiple. This is a great the "testing an API" and want to play with different values without have to copy-paste the Req Uest over and over, while maintaining (using the option) is 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 was vital that a developer was able to understand your product and consume your API easily. So why isn't prepare a bunch of API requests with pre-filled data for him to test different aspects?

At Mashape we have to document your APIs, and insert default values to kickstart the API development and consumption p Rocess. On top of this, we allow you to give meaningful response models to each call. This is when someone runs a query against an endpoint, there'll be no surprises! A good the understand how to structure your documentation are to has a bunch of endpoints with pre-filled values hosted Somewhere. And this is where the POSTMAN comes in handy, the can arrange API calls in folders called collections.

POSTMAN allows-collect a bunch of endpoints into a collection for later use. This is a great-to-get ready-to-deploy your documentation on Mashape as it gives the idea of which endpoints, param Eters and models you'll be using the when documenting your API.

Multiple Auth support

Nearly all APIs require a form of authentication.

    • Basic authentication–the Typical https://apikey:[email protected]/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 is checking response times, status codes and validating server responses. The Test suite allows to cut off on development lines of code written by developers to Test APIs, but it comes with a SMA ll cost as this feature are actually only available to paid the users at $9.99$ for a lifetime license.

2. HTTPie

If you work with APIs, your most probably has used cURL at least a couple for times in your life. CURL is extremely powerful, but a pain in the "back" 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": +, "Vegan": false} '-H ' content-type:application/jso N "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

The better right?

These is 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,[email protected] Request data fields to being serialized as a JSON object (default), or to is form-encoded (–form,-f).
Raw JSON fields field:=json,field:[email protected] Useful when sending JSON and one or more fields need to is a boolean,number, nested Object, or an Array, e.g., meals:= ' ["H Am "," spam "] ' or pies:=[1,2,3] (note the quotes).
Form File fields [email protected]/dir/file Only available With–form,-F. For example: [email protected]~/pictures/img.png. The presence of a file field results in a multipart/form-data request.

What is 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.