HTTPie is a command line tool that uses as an HTTP client, enabling us to consume Web Services with a simple, friendly syntax. In this tutorial, I will show you how to install and use it!
First, to install HTTPie, depending on the operating system you are using, you can run 1 of following statements:
– macOS:
1 |
brew install httpie |
or:
1 |
port install httpie |
– Linux:
1 |
apt-get install httpie |
or:
1 |
dnf install httpie |
or:
1 |
yum install httpie |
– On Window environment, you can use pip tool to install HTTPie.
See more about installing HTTPie here!
I’m using macOS so I will use HomeBrew tool to install it.
To check the results, run the command:
1 |
http --version |
Myself is as follows:
At this point, you can start using HTTPie.
The syntax of the http command is as follows:
1 |
http <flags> <HTTP_method> <URL> <request_data> |
Where:
- flags defines the options that HTTP will use to process for the request or display response.
- HTTP_method is the HTTP Method that we will use to request the Web Service. By default, if you do not pass this value, HTTPie will understand GET method if we do not transmit the request data, POST method if there is a request data.
- URL is the URL of the Web Service. For Web Services deployed in local machine, you don’t need to pass the localhost value. For example, if you have a Web Service at http://localhost:8080/hello, just only need to run “http: 8080/hello”.
- request_data is data we will send to Web Service.
I will use the example in the tutorial Hello World with Spark framework to consume by HTTPie! I will run the http command as follows:
1 |
http :4567/helloworld |
Result:
Find out more about how to use HTTPie here!