Httpie Command Line HTTP Tool: A User-Friendly API Testing and Debugging Client Implemented in Python

I remember when I first started in the industry, I was always overwhelmed by various API tests. Using curl meant remembering a ton of parameters, and using Postman was inefficient with its point-and-click interface.

Once, while debugging a payment interface, I needed to frequently test different parameter combinations. I wrote a bunch of scripts using curl, only to find syntax errors after a long search. A colleague recommended Httpie, saying it was simple and easy to use.

After trying it, I found it to be really great.

01

Httpie is a command line HTTP client written in Python, designed specifically for humans. Compared to those old tools like curl, its syntax is much more intuitive.

The most basic GET request looks like this:

# Normal GET request
http GET httpbin.org/get

# With query parameters
http GET httpbin.org/get name==ZhangSan age==25

You see, there’s no need to remember those complex parameters. The equals sign indicates query parameters, and two equals signs indicate URL parameters. This design is very intuitive for users.

Installation is also simple:

pip install httpie

Once installed, it’s ready to use.

02

POST requests are equally straightforward. I often test APIs in my projects like this:

# JSON format POST
http POST api.example.com/users name=LiSi [email protected] age:=28

# Note here that age:= indicates a numeric type
# = indicates a string, := indicates a non-string

File uploads are also very convenient:

# Upload file
http --form POST httpbin.org/post file@/path/to/file.jpg

# Send raw JSON
echo '{"name": "WangWu", "age": 30}' | http POST api.example.com/users

Once, I needed to test an image upload interface, and with Httpie, it was done in seconds. If I had used curl, it would have taken me a long time.

03

Httpie handles authentication particularly well. Basic authentication, API keys, and JWT tokens all have simple syntax:

# Basic authentication
http -a username:password GET api.example.com/protected

# Bearer token
http GET api.example.com/user Authorization:"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."

# Custom headers
http GET api.example.com/data X-API-Key:your-api-key

When integrating with the WeChat payment API, I often need to set various signature headers, and with Httpie, I can do it in one command, which is much faster than writing scripts.

The session feature is also very useful, allowing you to maintain a logged-in state:

# Create session
http --session=mysession POST api.example.com/login username=admin password=secret

# Use session
http --session=mysession GET api.example.com/profile

This way, you don’t have to log in every time.

04

The output format is also very considerate. By default, it highlights JSON responses and allows you to view only headers or body:

# View only response headers
http --headers GET httpbin.org/get

# View only response body  
http --body GET httpbin.org/get

# Detailed output including request and response
http --verbose GET httpbin.org/get

You can also save the response to a file:

http --download GET httpbin.org/image/png > image.png

This is particularly useful for debugging. I often use verbose mode to see the complete HTTP interaction process, which helps in locating issues.

Once, while troubleshooting a 502 error, I discovered through verbose mode that it was a request header format issue, and I quickly resolved it.

05

Advanced usage includes configuration files and a plugin system. You can set default parameters in ~/.httpie/config.json:

{
    "default_options": [
        "--style=monokai",
        "--timeout=60"
    ]
}

There are also various useful plugins, such as httpie-jwt-auth for handling JWT authentication:

pip install httpie-jwt-auth
http --auth-type=jwt --auth=secret GET api.example.com/protected

My suggestion is to start with the basic features; once you are familiar, you can explore the advanced features.

Compared to other tools, Httpie’s biggest advantage is its low learning curve, intuitive syntax, and friendly output. The downside is that its functionality is relatively simple, and for complex scenarios, you might still need to use curl or write code.

However, for daily API testing, Httpie is definitely sufficient and very efficient. Give it a try; once you use it, you won’t want to go back.

Leave a Comment