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:

$ http example.com

 

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.

$ http GET rootadminz.lan

 

Upload a File

This example shows how to upload a file to transfer.sh using input redirection.

$ http https://transfer.sh < file.txt

 

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 rootadminz.lan date='Hello World'

 

View Request Details

To see the request that is being sent, use -v option, for example.

$ http -v --form POST rootadminz.lan date='Hello World'

 

Basic HTTP Auth

HTTPie also supports basic HTTP authentication from the CLI in the form:

$ http -a username:password http://rootadminz.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.

$ http --help
OR
$ man  ttp

 

Hjalp dette svar dig? 0 Kunder som kunne bruge dette svar (0 Stem)