5 Fastest and Most Reliable Ways to Send HTTP Requests on Linux

On
A bundle of fiber glass wires

Developers and system administrators working in Linux environments often need to send HTTP requests in different scenarios. Whether it's an API testing routine or a network troubleshooting session, firing HTTP requests is one of the common tasks in these situations. In this tutorial, we'll discuss various methods to send HTTP requests in Linux. Both the command line tools, as well as programmatic options, will be discussed. Almost all of the tools mentioned below work seamlessly on all popular Linux distributions. Some of them come pre-bundled while others can be installed manually. Let's get started.

A bundle of fiber glass wires

I've used a Ubuntu laptop for testing all of these commands and tools. If you're using a different Linux distro, refer to the installation docs, in case you need to install a tool or library—manually.

Read Also:
10 Essential Commands for Linux VPS Administrators

Although there are several tools to send HTTP requests, I've picked the most popular options as they are stable and work without any issues. Without wasting any time, let's send HTTP requests.

1. cURL

It is undoubtedly one of the most popular command-line utilities to transfer data across the internet through different protocols. Sending an HTTP request is just one part of it. It's extremely popular, easy to use, and is blazingly fast.

The basic structure to send a cURL command is:

curl [options] [URL]

While sending an HTTP request, you can use the -X option to specify the request type, viz., GET, POST, PUT, DELETE, etc. Similarly, -H can be used to specify custom headers. And, in case you want to send data along with your HTTP request, use the -d option. Here's an example of a simple HTTP request.

curl https://twitter.com

This command line utility comes pre-bundled with almost every Linux distribution. It's open source and can be customized extensively for a specific use case.

2. HTTPie

This is a relatively new but powerful tool to send HTTP requests. Developers often use it as an API testing tool. When compared with cURL, it is a bit more user-friendly.

To send an HTTP request with the HTTPie utility, use the following command:

http [options] [METHOD] [URL]

Quite similar to cURL, the HTTPie tool supports all the necessary options, such as -h for adding headers, -d for sending data, and -f for formatting the result's output.

A simple HTTP request sent through HTTPie may look like this:

https www.rajeevedmonds.com

This tool is available both in the form of a desktop application and a command-line utility. And, other than Linux, it can be installed on other operating systems too.

3. HTTP Prompt

HTTP Prompt is an interactive command line utility for sending HTTP requests. It supports syntax highlighting and dynamic command completion popups. It's built on top of the HTTPie utility.

To start an interactive HTTP request session, use the following command:

http-prompt domain-name.com

This command lands you in an interactive command shell where you can invoke different HTTP commands including the addition of custom parameters to be used by a specific HTTP request.

You can apply different themes for its output. It also supports UNIX-like pipes to divert the output of one request into another one. It also integrates nicely with OpenAPI and Swagger which makes API endpoints exploration—easier.

4. Wget

One can also use the Wget package to send HTTP requests for file retrievals and mirroring entire websites. This one too comes pre-bundled with all Linux distributions.

The simplest way to download a web page through an HTTP request is:

wget https://www.yahoo.com

This command will save the downloaded web page in your current directory which you can either open in a web browser or can edit in a code editor. There are tons of switches available for this utility to tweak and customize your HTTP request.

It also supports FTP and FTPS protocols which can be used to transfer regular files from one server to another. Because it is a non-interactive command-line tool, system administrators often use it in scripts and cron jobs. It supports both HTTP proxies and HTTP cookies.

5. Apache Bench (ab)

As the name suggests, this powerful command-line tool is used to benchmark HTTP servers. It's a popular option among web administrators and developers to test and benchmark HTTP servers in both staging and production environments.

On a Ubuntu or Debian-based distribution, you can install it through the following command:

sudo apt-get install apache2-utils

Although it is primarily built for benchmarking, one can also use it to send simple HTTP requests.

If you're a user of cURL or HTTPie, you may not find this tool as flexible or user-friendly, when it comes to sending individual customized HTTP requests.

As an example, if you want to send a total of 250 HTTP requests with a concurrency level of 20, you can use the following command:

ab -n 250 -c 20 https://test-website.com/

You can also specify the timeout for the connections through the -t switch. It's one of the must-have tools for every web server administrator.

Conclusion

When it comes to Linux, there are numerous robust options available for sending HTTP requests. Command-line interfaces such as cURL and HTTPie offer convenient ways to interact with APIs and troubleshoot network problems swiftly.

For load testing or handling a substantial volume of concurrent requests, Apache Bench (ab) proves to be an invaluable tool.

Consider your specific requirements and select the method that aligns best with your needs. By doing so, you can experience the enhanced efficiency and reliability these tools bring to your Linux-based HTTP requests.