How to Test APIs and Web Apps From the Linux Terminal With HTTPie
Use HTTPie to test your web apps and API endpoints from the comfort of the Linux terminal.
If you’re developing a web app, you’ll need to test it. With HTTPie, you can test HTTP and other APIs from the Linux command line. Here’s how to get started.
What Is HTTPie?
HTTPie is an application meant for sending HTTP requests, as well as requests for RESTful web APIs to a remote server. Desktop and web-based versions for HTTPie are available too, but we’ll concentrate on the command-line version.
HTTP is the protocol underlying the web, including the page you’re reading now. In the protocol, requests come to a server from a user agent. This user agent is usually a web browser, but it doesn’t have to be.
Installing HTTPie on Linux
You can install HTTPie through many major Linux package managers. For example, on Debian and Ubuntu:
sudo apt install httpie
And on Arch Linux:
sudo pacman -S httpie
On the Red Hat family of distros, run:
sudo dnf install httpie
Using HTTPie to Test APIs on Linux
To start HTTPie, you need to call it from the command line using either of these two commands: http or https. The former uses HTTP and the latter uses encrypted HTTPS. Since most websites use HTTPS, you’ll want to use https on the command line.
To do a simple “GET” request, just use the URL as the argument:
You can also send a POST, which is useful if you’re developing a website with forms.
For example, if you wanted to pass the name “MUO” to a form, you’d use this command:
https example.com name="MUO"
HTTPie also works with JSON fields. If you wanted to set the name attribute, for example, run:
https PUT example.com name="MUO"
With HTTPie, you’ll have a tool for testing websites from the Linux command line. Linux is already popular for web development, being the main server OS in the market.
Linux and Unix have been the go-to OS for programmers and technical people for decades. Why is it so popular? It’s the way Linux is designed, and the availability of programming tools that makes it such a favorite of serious techies.