fbpx HTTPie Command in Linux: Modern Alternative to curl for APIs | Certificação Linux

HTTPie Command in Linux: Modern Alternative to curl for REST APIs

📅 12/06/2021 ⏱ 2 min ✍️ Uira Ribeiro
Linuxcommands
HTTPie Command in Linux: Modern Alternative to curl for REST APIs
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

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 Javascript Backend web applications.

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

To install on Ubuntu or on Debian:

$ apt-get install httpie

To install on Red Hat/CentOS/Fedora:

$ yum install httpie

Once installed, its use is simple, just inform the URL:

$ http 'https://api.openweathermap.org/data/2.5/weather?q=Belo%20Horizonte,PT&appid=9908ae7bbb3c530f54efdec77ac3ccde' HTTP/1.1 200 OKAccess-Control-Allow-Credentials: trueAccess-Control-Allow-Methods: GET, POSTAccess-Control-Allow-Origin: *Connection: keep-aliveContent-Length: 476Content-Type: application/json; charset=utf-8Date: Tue, 12 May 2020 22:26:42 GMTServer: openrestyX-Cache-Key: /data/2.5/weather?q=belo%20horizonte,pt{    "base": "stations",    "clouds": {        "all": 81    },

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

It allows passing POST parameters:

$ http -f POST httpbin.org/post hello=WorldHTTP/1.1 200 OKAccess-Control-Allow-Credentials: trueAccess-Control-Allow-Origin: *Connection: keep-aliveContent-Length: 488Content-Type: application/jsonDate: Tue, 12 May 2020 22:32:16 GMTServer: 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 simply, using redirection:

$ http httpbin.org/post < arquivo.json

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

$ http httpbin.org/image/png > image.webp

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

Liked it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp