Comando httpie no Linux (baixar arquivos) [Guia Básico]
O comando httpie no Linux é parecido com o CURL, mas seu uso é mais simples. Ele permite baixar arquivos, e também conectar em API's web para testar aplicações web do tipo REST ou Backend Javascript.
Ela permite interagir com servidores HTTP, RESTful APIs, e web services.
Para instalar no Ubuntu ou no Debian:
$ apt-get install httpie
Para instalar no Red Hat/CentOS/Fedora:
$ yum install httpie
Uma vez instalada, seu uso é simples, bastando informar a 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 },
O comando http já faz o trabalho de informar o cabeçalho e formatar o JSON, sem a necessidade de informa parâmetros e comandos adicionais.
Ela permite passar parâmetros POST:
$ 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"}
Um arquivo pode ser enviado também de forma simples, usando redirecionamento:
$ http httpbin.org/post < arquivo.json
Da mesma forma, um arquivo pode ser baixado e salvo usando o redirecionamento de saída:
$ http httpbin.org/image/png > image.webp
Aprenda muito mais sobre Linux em nosso curso online. Você pode efetuar a matrícula aqui. Se você já tem uma conta, ou quer criar uma, basta entrar ou criar seu usuário aqui.