HTTPie

在 API 时代,像现代的、用户友好的命令行 HTTP 客户端一样简单。JSON 支持,颜色,会话,下载,插件及更多。「As easy as /aitch-tee-tee-pie/ Modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more. https://twitter.com/clihttp」

Github星跟蹤圖

HTTPie:API 时代的人性化 CLI HTTP 客户端

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

1 关于本文件

本文档最好在 httpie.org/docs 上查看,在那里你可以选择相应的 HTTPie 版本,也可以使用 termible.io 嵌入式终端从浏览器直接运行示例。如果你是在 GitHub 上阅读这篇文章,那么这篇文章涵盖了当前的开发版本。我们邀请您通过编辑 README.rst 来提交对文档的修正和改进。

2 主要特性

  • 表现力强且直观的语法
  • 格式化和彩色化的终端输出
  • 内置JSON支持
  • 表格和文件上传
  • HTTPS、代理和认证
  • 任意请求数据
  • 自定义页眉
  • 持久性会议
  • 类似Wget的下载
  • 支持Linux、MacOS和Windows
  • 插件
  • 文件资料
  • 测试范围

3 安装

3.1 macOS

在 macOS 上,可以通过 Homebrew 安装 HTTPie(推荐)。

$ brew install httpie

也可以使用 MacPorts port。

$ port install httpie

3.2 Linux

大多数 Linux 发行版都提供了一个可以使用系统包管理器安装的软件包,例如。

# Debian, Ubuntu, etc.
$ apt install httpie
# Fedora
$ dnf install httpie
# CentOS, RHEL, ...
$ yum install httpie
# Gentoo
$ emerge httpie
# Arch Linux
$ pacman -S httpie

3.3 Windows 等。

一个通用的安装方法(适用于 Windows、Mac OS X、Linux......,并且总是提供最新版本)是使用 pip。

# 确保我们有一个最新版本的 pip 和 setuptools。
$ pip install --upgrade pip setuptools
$ pip install --upgrade httpie

(如果 pip 安装失败,你可以尝试 easy_install httpie 作为后备。)

3.4 Python 版本

需要 Python 3.6 或更高版本。

3.5 不稳定版本

你也可以直接从 GitHub 上的主分支安装最新的未发布的开发版本。这是一个未来稳定版的工作过程,所以体验可能会不太顺畅。

在 macOS 上,你可以用 Homebrew 安装它。

$ brew install httpie --HEAD

否则用 pip 安装。

$ pip install --upgrade https://github.com/jakubroztocil/httpie/archive/master.tar.gz

验证现在我们有了当前的开发版本标识,后缀为 -dev,例如。

$ http --version
# 2.0.0-dev

4 用法

Hello World:

$ http https://httpie.org/hello

概要:

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

请参见 http --help。

(详细用法请参见自述文件)

26 Meta

26.1 接口设计

命令参数的语法与实际通过网线发送的HTTP请求紧密对应。它的优点是容易记忆和阅读。通常只需将请求元素内联,就可以将一个HTTP请求翻译成 HTTPie 参数列表。例如,比较一下这个 HTTP 请求。

POST /post HTTP/1.1
Host: httpbin.org
X-API-Key: 123
User-Agent: Bacon/1.0
Content-Type: application/x-www-form-urlencoded

name=value&name2=value2

使用HTTPie命令发送它

$ http -f POST httpbin.org/post \
  X-API-Key:123 \
  User-Agent:Bacon/1.0 \
  name=value \
  name2=value2

请注意,无论是元素的顺序还是语法都非常相似,命令中只有一小部分是用来控制 HTTPie 的,并不直接对应任何部分的请求(这里只是 -f 要求 HTTPie 发送表单请求)。

两种模式,--pretty=all(终端默认)和 --pretty=none(重定向输出默认),允许用户友好的交互式使用和来自脚本的使用,其中 HTTPie 作为一个通用的HTTP客户端。

由于 HTTPie 还在大力开发中,在 HTTPie 达到最终的 1.0 版本之前,现有的命令行语法和一些-- OPTIONS 可能会有一些变化。所有的变化都会记录在变更日志中。

26.2 用户支持

请使用以下支持渠道。

26.3 相关项目

26.3.1 依赖性

在底层,HTTPie使用了这两个惊人的库。

  • Requests — Python HTTP library for humans
  • Pygments — Python 语法高亮显示器

26.3.2 HTTPie 的朋友

HTTPie 与以下工具配合得非常好。

  • http-prompt — HTTPie 的交互式 shell,具有自动完成和命令语法高亮功能。
  • jq — CLI JSON 处理器,可与HTTPie配合使用。

帮助从其他客户端工具转换。

  • CurliPie 帮助将 cURL 命令行转换为 HTTPie 命令行。

26.3.3 替代品

  • httpcat — HTTPie 的低级姊妹工具,用于在命令行上构建原始 HTTP 请求。
  • curl — 一个 "瑞士刀 "命令行工具,也是一个用 URL 传输数据的特殊库。

26.4 贡献

参见 CONTRIBUTING.rst

26.5 变更日志

参见 CHANGELOG

26.6 艺术品

26.7 许可证

BSD-3-Clause: LICENSE

26.8 作者

Jakub Roztocil@jakubroztocil)创建了 HTTPie,这些优秀的人也做出了贡献。

 

(The first version translated by vz on 2020.08.21)

 

主要指標

概覽
名稱與所有者httpie/cli
主編程語言Python
編程語言Makefile (語言數: 5)
平台Linux, Mac, Windows
許可證BSD 3-Clause "New" or "Revised" License
所有者活动
創建於2012-02-25 12:39:13
推送於2024-12-17 17:30:35
最后一次提交2024-12-17 17:30:35
發布數50
最新版本名稱3.2.4 (發布於 )
第一版名稱0.1.4 (發布於 )
用户参与
星數35.3k
關注者數87
派生數3.7k
提交數1.8k
已啟用問題?
問題數884
打開的問題數166
拉請求數406
打開的拉請求數21
關閉的拉請求數195
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

HTTPie for Desktop


Twitter
Chat

Docs
Latest version
Build
Coverage
PyPi downloads

HTTPie (pronounced aitch-tee-tee-pie) is a command-line HTTP client.
Its goal is to make CLI interaction with web services as human-friendly as possible.
HTTPie is designed for testing, debugging, and generally interacting with APIs & HTTP servers.
The http & https commands allow for creating and sending arbitrary HTTP requests.
They use simple and natural syntax and provide formatted and colorized output.

We lost 54k GitHub stars

Please note we recently accidentally made this repo private for a moment, and GitHub deleted our community that took a decade to build. Read the full story here: https://httpie.io/blog/stardust

Getting started

Features

  • Expressive and intuitive syntax
  • Formatted and colorized terminal output
  • Built-in JSON support
  • Forms and file uploads
  • HTTPS, proxies, and authentication
  • Arbitrary request data
  • Custom headers
  • Persistent sessions
  • wget-like downloads

See all features →

Examples

Hello World:

https httpie.io/hello

Custom HTTP method, HTTP headers and JSON data:

http PUT pie.dev/put X-API-Token:123 name=John

Build and print a request without sending it using offline mode:

http --offline pie.dev/post hello=offline

Use GitHub API to post a comment on an Issue with authentication:

http -a USERNAME POST https://api.github.com/repos/httpie/cli/issues/83/comments body='HTTPie is awesome! :heart:'

See more examples →

Community & support

Contributing

Have a look through existing Issues and Pull Requests that you could help with. If you'd like to request a feature or report a bug, please create a GitHub Issue using one of the templates provided.

See contribution guide →