Get the code: learn-httpie.sh
HTTPie is a powerful command-line HTTP client designed for easy interaction with HTTP servers. It provides a simple and intuitive interface, making it an excellent tool for developers, testers, and system administrators.
HTTPie follows a simple syntax: http [flags] [METHOD] URL [items].
http GET https://api.example.com/posts
You can print the request without sending it by using the --offline
flag.
http --offline https://api.example.com/posts
localhost
HTTPie supports a curl-like shorthand for localhost. For instance, :3000
expands to http://localhost:3000
. If the port is omitted, it assumes port 80.
http :/users # http://localhost/users
http :5000/rss # http://localhost:5000/rss
If you don't specify the METHOD, the HTTPie will use:
http https://api.example.com/tags # GET tags
http https://api.example.com/tags title="Tutorial" slug="tutorial" # POST a new tag
If you're manually adding query string parameters in the terminal, try the
param==value
syntax. It avoids shell escaping for & separators and
automatically URL-escapes special characters in parameter names and values.
This differs from parameters in the full URL, which HTTPie doesn't modify.
http https://api.example.com/search q==httpie per_page==20
You can send data in various formats such as JSON, form data, or files.
http POST https://api.example.com/posts title="Hello" body="World"
http -f POST https://api.example.com/submit name=John email=[email protected]
http --form POST https://api.example.com/upload file@/path/to/file.txt
HTTPie allows you to set headers and handle authentication easily.
http GET https://api.example.com/posts Authorization:"Bearer Token" User-Agent:"HTTPie"
http -a username:password GET https://api.example.com/protected
https -A bearer -a token https://api.example.com/admin
HTTPie provides various options for handling responses.
http GET https://api.example.com/data Accept:application/json # Pretty Print JSON
http GET https://api.example.com/image --output image.png # Save Response to File
http --follow GET https://example.com # Follow Redirects
Got a suggestion? A correction, perhaps? Open an Issue on the GitHub Repo, or make a pull request yourself!
Originally contributed by Adaías Magdiel, and updated by 2 contributors.