- HTTPie – A Modern HTTP Client Similar to Curl and Wget Commands
- How to Install and Use HTTPie in Linux
- Send a HTTP Method
- Upload a File
- Download a File
- Submit a Form
- View Request Details
- Basic HTTP Auth
- Custom HTTP Headers
- Monitor All HTTP Requests (like TCPdump) On a Linux Server with httpry
- Want to subscribe to the cron.weekly newsletter?
- Who dis? 🤔
- How to send HTTP request using curl and wget command from Linux and UNIX? Example Tutorial
- Linux Command to send HTTP GET request
- UNIX command to Send an HTTP POST request
HTTPie – A Modern HTTP Client Similar to Curl and Wget Commands
HTTPie (pronounced aitch-tee-tee-pie) is a cURL-like, modern, user-friendly, and cross-platform command line HTTP client written in Python. It is designed to make CLI interaction with web services easy and as user-friendly as possible.
It has a simple http command that enables users to send arbitrary HTTP requests using a straightforward and natural syntax. It is used primarily for testing, trouble-free debugging, and mainly interacting with HTTP servers, web services and RESTful APIs.
- HTTPie comes with an intuitive UI and supports JSON.
- Expressive and intuitive command syntax.
- Syntax highlighting, formatted and colorized terminal output.
- HTTPS, proxies, and authentication support.
- Support for forms and file uploads.
- Support for arbitrary request data and headers.
- Wget-like downloads and extensions.
- Supports ython 2.7 and 3.x.
In this article, we will show how to install and use httpie with some basic examples in Linux.
How to Install and Use HTTPie in Linux
Most Linux distributions provide a HTTPie package that can be easily installed using the default system package manager, for example:
# apt-get install httpie [On Debian/Ubuntu] # dnf install httpie [On Fedora] # yum install httpie [On CentOS/RHEL] # pacman -S httpie [On Arch Linux]
Once installed, the syntax for using httpie is:
$ http [options] [METHOD] URL [ITEM [ITEM]]
The most basic usage of httpie is to provide it a URL as an argument:
Now let’s see some basic usage of httpie command with examples.
Send a HTTP Method
You can send a HTTP method in the request, for example, we will send the GET method which is used to request data from a specified resource. Note that the name of the HTTP method comes right before the URL argument.
Upload a File
This example shows how to upload a file to transfer.sh using input redirection.
Download a File
You can download a file as shown.
$ http https://transfer.sh/Vq3Kg/file.txt > file.txt #using output redirection OR $ http --download https://transfer.sh/Vq3Kg/file.txt #using wget format
Submit a Form
You can also submit data to a form as shown.
$ http --form POST tecmint.lan date='Hello World'
View Request Details
To see the request that is being sent, use -v option, for example.
$ http -v --form POST tecmint.lan date='Hello World'
Basic HTTP Auth
HTTPie also supports basic HTTP authentication from the CLI in the form:
$ http -a username:password http://tecmint.lan/admin/
Custom HTTP Headers
You can also define custom HTTP headers in using the Header:Value notation. We can test this using the following URL, which returns headers. Here, we have defined a custom User-Agent called ‘strong>TEST 1.0’:
$ http GET https://httpbin.org/headers User-Agent:'TEST 1.0'
See a complete list of usage options by running.
You can find more usage examples from the HTTPie Github repository: https://github.com/jakubroztocil/httpie.
HTTPie is a cURL-like, modern, user-friendly command line HTTP client with simple and natural syntax, and displays colorized output. In this article, we have shown how to install and use httpie in Linux. If you have any questions, reach us via the comment form below.
Monitor All HTTP Requests (like TCPdump) On a Linux Server with httpry
Wouldn’t it be really cool if you could run a tool like tcpdump and see all HTTP requests flowing over the network, in a readable form?
Because let’s be honest, something like this is far from readable.
$ tcpdump -i eth0 port 80 -A 20:56:08.793822 IP 172.28.128.1.49781 > 172.28.128.3.http: Flags [S], seq 1641176060, win 65535, options [mss 1460,nop,wscale 5,nop,nop,TS val 1225415667 ecr 0,sackOK,eol], length 0 E..@V.@.@. u.Pa.[. -. .
It tells you that something is flowing over the wire, but you sure as hell can’t read what is going over it. You recognise keywords, but that’s it.
There are tools out there that do a better job, like httpry.
It’s been around long enough to be present in most repositories on Linux servers by now. Install it via your package manager of choice.
$ yum install httpry $ apt-get install httpry
After you have it installed, you can run it on your server and sniff for HTTP calls.
$ httpry -i eth0 172.28.128.1 172.28.128.3 > HEAD ma.ttias.be / HTTP/1.1 - - 172.28.128.3 172.28.128.1 < - - - HTTP/1.1 301 Moved Permanently
To output above is the result of the following HTTP call.
$ curl -I 172.28.128.3 -H "Host: ma.ttias.be"
It did a HEAD request ( -I ) and got a 301 HTTP redirect back.
Want to see how many HTTP requests are flowing through per second and which vhost is the most active? Start httpry with the -s parameter.
$ httpry -i eth0 -s . 2015-08-06 21:06:56 infinite-download.ma.ttias.be 19 rps 2015-08-06 21:06:56 enginehack.ma.ttias.be 61 rps 2015-08-06 21:06:56 totals 30.69 rps 2015-08-06 21:07:01 infinite-download.ma.ttias.be 21 rps 2015-08-06 21:07:01 enginehack.ma.ttias.be 56 rps 2015-08-06 21:07:01 totals 32.41 rps
Every 5 seconds, the output shows the requests made in that last interval. It shows the Host: headers used in that request and the amount of requests that were received.
While it doesn’t work on HTTPS requests, it is a useful tool to have in your arsenal.
Want to subscribe to the cron.weekly newsletter?
I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.
It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.
No spam. Just some good, practical Linux & open source content.
Who dis? 🤔
Hi! I'm Mattias Geniar, an independent developer, Linux sysadmin & general problem solver. Looking for help? I'm available for hire as a consultant. Want to get in touch? Have a look at my contact page.
How to send HTTP request using curl and wget command from Linux and UNIX? Example Tutorial
You can use either curl or wget command to send HTTP requests from UNIX or Linux operating system. Both commands allow you to send GET and POST requests, which means you can also call REST web services. I have a Java web application, which runs on Linux and exposes WebServices. I was writing a UNIX script to download In some data from that web service when I hit by the question, how do I make an HTTP call from UNIX? What is the UNIX command should I use? If you are also facing the same problem, then you have come to the right ht place. Basically, you can use two UNIX commands to make the HTTP request, wget , and curl .
You can use curl and wget to send both GET and POST HTTP requests. My use case was rather simple, I just need to make a GET call to web service to download the data, but these two commands are mighty and provide many different options to interact with the web using HTTP right from the shell.
Between wget and curl (also known as cURL), curl (I call it "karl") is my favorite. Why? I think because I have used it more often than wget :-).
You can make your choices if you have good knowledge of the Linux command line, and that's why I suggest every programmer and software developer join Learn Linux in 5 Days and Level Up Your Career course on Udemy, the best way to become efficient in Linux.
Now let's see how to send HTTP requests from UNIX using the curl command.
Linux Command to send HTTP GET request
Here is one example of calling web service from Linux shell by sending HTTP GET request using cURL command:
$ curl http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=bd82977b86bf27fb59a04b61b657fb6f "coord":"lon":-0.13,"lat":51.51>,"weather":[ "id":804,"main":"Clouds","description":"overcast clouds","icon":"04n">], "base":"stations", "main":"temp":282,"pressure":1022,"humidity":87,"temp_min":277.15,"temp_max":285.15>, "visibility":10000,"wind":"speed":1.5>,"clouds":"all":90>,"dt":1445577409, "sys":"type":1,"id":5093,"message":0.0201,"country":"GB", "sunrise":1445582275,"sunset":1445619056>,"id":2643743,"name":"London","cod":200>
You can also specify timeout using - m option as shown below:
$ curl -m 2 http://api.openweathermap.org/data/2.5/weather ?q=London,uk&appid=bd82977b86bf27fb59a04b61b657fb6f
This request will timeout in 2 seconds if it doesn't receive any response.
You can also use wget to send HTTP requests and download the data. The only difference between curl and wget is that curl will print output in console and wget will store it in the file e.g.
$ wget http://localhost:8080/index.html
will download the content of index.html and store it into a file with the same name.
Here is how you can use curl to download wget command in UNIX:
UNIX command to Send an HTTP POST request
You can also use curl to send HTTP post requests. All you need to do is use the --data option to specify the data you want to POST to web service e.g.
$ curl --data "param1=value1¶m2=value2" http://locahost:8080/weather
if you want to send data from file to web service, you can also use the following command:
$ curl -X POST -d @filename http://locahost:8080/weather
Similarly, if you're going to upload a file, you can do so by executing the following command:
$ curl --form "fileupload=@filename.txt" http://locahost:8080/weather
Btw, these are just the tip of the iceberg when it comes to seeing the real power of curl command. If you want to learn more, I suggest you check out the Linux Command Line Basics course on Udemy. One of the best courses to learn basic and advanced Linux commands.
That's all about how to send HTTP requests from UNIX and Linux. It's simple, just remember the curl and wget command. You can explore their option by using man wget and man curl. Also, remember the difference between curl and wget, the former prints the output in the console while the later store the response in the same file as requested. I personally like curl because it's easier to use but if you like wget stick with it.
- 10 examples of find command in UNIX (examples)
- 10 examples of grep command in UNIX (examples)
- 10 examples of date command in Linux (examples)
- How to get an IP address from the hostname and vice-versa in Linux (command)
- 10 examples of xargs command in Linux (examples)
- 10 Courses to learn Linux commands for beginners (best courses)
- 10 examples of tar command in UNIX (examples)
- 10 examples of Vim in UNIX (examples)
- How to create, update and delete soft link in UNIX (command)
- How to delete empty files and directory in UNIX (solution)
- How to make a directory tree in one command? (example)
- How to how long argument of a process in Solaris (command)
- UNIX command to find out how long a process is running? (answer)
- UNIX command to find the size of the file and directory? (command)
- 5 examples of sort command in Linux (examples)
- 5 examples of kill command in Linux (examples)
- 10 examples of chmod command in UNIX (examples)
- 10 tips for working fast in UNIX? (tips)
P. S. - If you want to learn Linux and looking for some free resources like books and online courses, then you can also check out this list of free Linux courses for Programmers and IT Professionals. This list contains some of the best free courses from Udemy, Pluralsight, Coursera, Codecademy, and other online platforms.