Github每日精选(第84期):命令行 HTTP 客户端HTTPie

HTTPie

HTTPie for Terminal:面向 API 时代的人性化 CLI HTTP 客户端,HTTPie(发音为aitch-tee-tee-pie)是一个命令行 HTTP 客户端。它的目标是使 CLI 与 Web 服务的交互尽可能人性化。HTTPie 设计用于测试、调试以及通常与 APIHTTP服务器交互。http&https命令允许创建和发送任意 HTTP 请求。它们使用简单自然的语法,并提供格式化和彩色输出。

在这里插入图片描述

安装

安装之前确保自己的python 版本在 3.7以上。用python --version 可以参看python 的版本。

安装

# Install httpie
python -m pip install --upgrade pip wheel
python -m pip install httpie

更新

# Upgrade httpie
python -m pip install --upgrade pip wheel
python -m pip install --upgrade httpie

macOS 下的安装:

# Install httpie
brew update
brew install httpie

# Upgrade httpie
brew update
brew upgrade httpie

ubuntu 下的安装:

# Install httpie
curl -SsL https://packages.httpie.io/deb/KEY.gpg | apt-key add -
curl -SsL -o /etc/apt/sources.list.d/httpie.list https://packages.httpie.io/deb/httpie.list
apt update
apt install httpie

使用实例

我们还是从最简单的hello world开始:

https httpie.io/hello

得到的结果如下:

HTTP/1.1 200 OK
Age: 0
Cache-Control: public, max-age=0, must-revalidate
Connection: keep-alive
Content-Length: 264
Content-Type: application/json; charset=utf-8
Date: Wed, 26 Oct 2022 01:57:50 GMT
Etag: "108-yw+Xn8xsGAsJIUMQvDLN7gAcQuc"
Server: Vercel
Strict-Transport-Security: max-age=63072000
X-Matched-Path: /api/hello
X-Vercel-Cache: MISS
X-Vercel-Id: hnd1::iad1::9dtl2-1666749470755-c32d10172552

{
    "ahoy": [
        "Hello, World! 👋 Thank you for trying out HTTPie 🥳",
        "We hope this will become a friendship."
    ],
    "links": {
        "discord": "https://httpie.io/discord",
        "github": "https://github.com/httpie",
        "homepage": "https://httpie.io",
        "twitter": "https://twitter.com/httpie"
    }
}

命令的格式如下:

http [flags] [METHOD] URL [ITEM [ITEM]]

http方法:

http -f POST pie.dev/post hello=World

结果如下:

HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
CF-Cache-Status: DYNAMIC
CF-RAY: 75ffa69b3cde5281-LAX
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json
Date: Wed, 26 Oct 2022 02:09:36 GMT
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=1qOC9CYUvezMJFcoJDMgBy8jegWrUGL8gJKyFlFWQVYgp5%2BjUug8TqCMDPv%2FspfQOp%2FUn%2B9RBPHdyXGDEH7FTZAgkpLImt9%2BWo%2BDSbSKKct5xHnRtKTxKlZ7"}],"group":"cf-nel","max_age":604800}
Server: cloudflare
Transfer-Encoding: chunked
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

{
    "args": {},
    "data": "",
    "files": {},
    "form": {
        "hello": "World"
    },
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip",
        "Cdn-Loop": "cloudflare",
        "Cf-Connecting-Ip": "125.77.202.250",
        "Cf-Ipcountry": "CN",
        "Cf-Ray": "75ffa69b3cde5281-FRA",
        "Cf-Visitor": "{\"scheme\":\"http\"}",
        "Connection": "Keep-Alive",
        "Content-Length": "11",
        "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
        "Host": "pie.dev",
        "User-Agent": "HTTPie/3.2.1"
    },
    "json": null,
    "origin": "125.77.202.250",
    "url": "http://pie.dev/post"
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

go2coding

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值