Categories: How-To

httpie command on Linux (download files) [Basic Guide]

The httpie command on Linux is similar to CURL, but its use is simpler. It allows you to download files and also connect to web APIs to test REST or Backend Javascript web applications.

It allows you to interact with HTTP servers, RESTful APIs, and web services.

To install on Ubuntu or Debian:

$ apt-get install httpie

To install on Red Hat/CentOS/Fedora:

$ yum install httpie

Once installed, its use is simple, simply enter the URL:

$ http 'https://api.openweathermap.org/data/2.5/weather?q=Belo%20Horizonte,PT&appid=9908ae7bbb3c530f54efdec77ac3ccde' 
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST
Access-Control-Allow-Origin: *
Connection: keep- alive
Content-Length: 476
Content-Type: application/json; charset=utf-8
Date: Tue, 12 May 2020 22:26:42 GMT
Server: openresty
X-Cache-Key: /data/2.5/weather? q=belo%20Horizonte, pt

{
“base”: “stations”,
“clouds”: {
“all”: 81
},

The http command already does the job of entering the header and formatting the JSON, without the need to enter additional parameters and commands.

It allows you to pass POST parameters:

$ http -f POST httpbin.org/post hello=World 
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 488
Content-Type: application/json
Date: Tue, 12 May 2020 22:32:16 GMT
Server: gunicorn/19.9.0
{
“args”: {},
“data”: “”,
“files”: {},
“form”: {
“hello”: “World”
},
“headers”: {
“Accept”: “*/*”,
“Accept-Encoding”: “gzip , deflate”,
“Content-Length”: “11",
“Content-Type”: “application/x-www-form-urlencoded; charset=utf-8",
“Host”: “httpbin.org”,
“User-Agent”: “HTTPIE/2.1.0",
“X-Amzn- Trace-Id”: “root=1-5ebb23f0-c052d8b2169a5304df2fee88"

},
“json”: null,
“origin”: “192.241.133.165″,
“url”: “http://httpbin.org/post”
}

A file can also be sent in a simple way, using redirection

:

$ http httpbin.org/post < file.json

Likewise, a file can be downloaded and saved using output redirection:

$ http http://bin.org/image/png > image.png

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Share
Published by
Uirá Endy Ribeiro

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.