Stop Using curl! httpie Teaches You to Make Smoother HTTP Requests

In daily development, almost every backend developer, frontend developer, or testing engineer frequently deals with HTTP requests. Whether debugging interfaces, checking responses, or testing server behavior, the most commonly used tool is probably <span>curl</span>. However, many people find the syntax of <span>curl</span> unintuitive, the output unattractive, and reading it cumbersome. Is there a more elegant and user-friendly way to send HTTP requests and view results? The answer is httpie! It is a modern, command-line-friendly HTTP client that makes writing requests as simple as speaking, with beautifully highlighted results. Today, I will guide you from zero to one in mastering httpie.

What is httpie?

<span>httpie</span> is a modern, easy-to-use, powerful command-line tool for interacting with web services. It provides a friendlier and more readable experience than <span>curl</span>, supporting request highlighting, concise output, and more intuitive parameter syntax.

In summary:httpie = the command-line tool that makes you love writing HTTP requests.

Core Concepts

  • Concise Syntax: Uses a “key=value” style to pass request parameters.
  • Highlighted Output: Automatically beautifies JSON or other format responses for easier reading.
  • Supports Various HTTP Methods: Easily write GET, POST, PUT, DELETE, etc.

Why Choose httpie?

  • ✅ Simple syntax and strong readability, much more user-friendly than <span>curl</span>.
  • ✅ Response results are automatically highlighted, making it ideal for debugging RESTful APIs.
  • ✅ Supports file uploads, setting headers, authentication, and more, with flexible configuration.
  • ✅ Active community, clear documentation, and easy to learn.

Installation Method

pip install httpie

Or use brew (macOS):

brew install httpie

After installation, you can use the <span>http</span> command directly.

Quick Experience: Initiate a GET Request

First, let’s experience the most basic usage:

http GET https://jsonplaceholder.typicode.com/posts/1

The output will automatically highlight JSON and format it for clarity.

Send a POST Request

Suppose you want to send JSON data to an interface, just use <span>key=value</span>.

http POST https://jsonplaceholder.typicode.com/posts title="My Title" body="This is content" userId=1

httpie will automatically package the data into JSON format and return the newly created resource in the response.

Add Custom Header

http GET https://httpbin.org/headers X-Token:123456

The syntax is very intuitive, <span>X-Token:123456</span> will automatically be added as a header to the request.

Basic Authentication

Some interfaces require authentication, and httpie also supports a very elegant way, for example:

http -a username:password GET https://httpbin.org/basic-auth/username/password

This will automatically use HTTP Basic Auth for the request.

Upload Files

To upload a file, such as an image to a server, just use the <span>@</span> symbol.

http -f POST https://httpbin.org/post [email protected]

Here, <span>-f</span> indicates using form format (multipart/form-data), and <span>[email protected]</span> will attach the file to the request body.

Save Response Content to File

If you want to save the returned content to a local file, you can write:

http GET https://example.com/file.zip --download

Or directly redirect to save:

http GET https://example.com/file.zip &gt; file.zip

Specify Output Format

By default, httpie automatically highlights and formats output. If you want the raw response (for debugging headers):

http --pretty=none GET https://httpbin.org/get

Use Environment Variables

Using variables in commands is also convenient, for example:

export TOKEN="abc123"
http GET https://httpbin.org/headers Authorization:"Bearer $TOKEN"

This allows for more flexible calls in scripts or CI pipelines.

Learning Notes

  • If the interface returns content that is not JSON, you can use <span>--raw</span> to view the raw response body.
  • To pass complex JSON objects, you can use <span>:=</span>, for example:<span>data:='{"a":1,"b":2}'</span>.
  • It does not support calling multiple URLs at once like <span>curl</span>, but you can write scripts for batch execution.

Other Powerful Features

  • ✅ You can extend functionality using the <span>httpie plugins</span> mechanism, such as automatic signing and OAuth support.
  • ✅ Supports cookie session management, convenient for processes that require continuous API calls.
  • ✅ Works with alias to write short commands for frequently used interfaces, improving efficiency.

Application Scenarios

  • Local debugging of backend interfaces
  • Debugging third-party REST APIs
  • Simulating client requests (such as mobile or frontend calls)
  • Quickly checking headers, authentication processes, and cross-origin behaviors
  • Writing automation scripts or testing interface data

Extra Benefits

If you combine httpie with jq (a JSON parsing tool), you can perform more complex chained operations on interfaces, such as automatically parsing return values and using them as parameters for the next interface; combined with zsh alias or scripts, you can streamline repetitive interface requests into a single command, greatly improving daily testing and debugging efficiency!

Conclusion

httpie is a powerful, smooth, and low-learning-cost HTTP command-line tool. Whether you are a beginner quickly debugging APIs or an experienced developer writing automated tests, it can be used with ease. If this article has helped you or if you encounter any issues during use, feel free to leave a comment or message me. I will respond promptly to help you out, and together we can create a cooler and more efficient Python development toolchain!

Leave a Comment