HTTPie CLI のインストール:GET/POST、ヘッダ・JSON body、curl との対照

http を入れ、GET/POST と JSON を送り、curl 対応を把握する。

REST API の手元デバッグでは curl は万能ですがフラグが増えがちです。HTTPie(http)は GET/POST・ヘッダ・JSON body を読みやすい構文で送り、応答 JSON を既定で整形表示します。本稿は macOS/Linux/Windows のインストール、GET/POST 例、ヘッダと JSON、curl との対照 を hereink 向けにまとめます。

検索語はHTTPie CLI のインストールと GET POST で JSON を送る。http を入れ、公開 API へ最初の GET/JSON POST ができ、curl 相当が分かれば OK です。

導入brew · pip · apt
リクエストGET · POST · JSON
対照http vs curl

HTTPie が解くこと

読みやすい CLI HTTP

http GET api.example.com/users でメソッドと URL が分離。JSON は色付き整形。

jq と組み合わせ

http GET … | jq '.data'。jq 記事は変換、HTTPie は送信担当。

公式:github.com/httpie/cli、httpie.io/docs/cli。http --version で確認。

インストール

  1. 1
    macOS(Homebrew)

    brew install httpie。

  2. 2
    Linux

    sudo apt install httpie または pip install --user httpie。

  3. 3
    Windows

    winget install httpie.httpie または pip。

  4. 4
    最初の GET

    http GET https://httpbin.org/get。

GET とクエリ

http GET https://httpbin.org/get
http GET https://httpbin.org/get page==2 limit==10
http --body GET https://httpbin.org/uuid

POST と JSON

http POST https://httpbin.org/post name=Ada role=admin
http POST https://httpbin.org/post tags:='["go","rust"]'
http --form POST https://httpbin.org/post email=test@example.com

= は文字列、:= は JSON リテラル。

ヘッダ

http GET https://httpbin.org/headers Authorization:"Bearer TOKEN" Accept:application/json

HTTPie と curl

目的HTTPiecurl
GET JSONhttp GET urlcurl -s url | jq .
POST JSONhttp POST url name=Adacurl -X POST -H 'Content-Type: application/json' -d '…' url
ヘッダAuthorization:"Bearer x"curl -H 'Authorization: Bearer x'
向く
手動 API 探索、README 用サンプル、jq との JSON デバッグ。
向かない
複雑 OAuth、クライアント証明書、ブラウザ Cookie 完全再現。
コマンド名は http?

パッケージ名 httpie、実行ファイルは http / https。

スクリプト向け出力?

--body や --print=b、必要なら --check-status。

curl 完全置換?

日常 JSON REST は HTTPie、レガシー脚本と低レベルは curl を併用。

API が見えたら図で揃える

スペースの作り方。

今すぐ開始