Skip to the content.

HTTPie
Modern, user-friendly, programmable and filterable command-line HTTP client for the API

HTTPy is a command line HTTP client. Its purpose is to make duplicate web requests on a single line. httpy is designed for testing, debugging, and generally interacting with APIs and HTTP servers. The httpy command allows creating and sending arbitrary HTTP requests. They use simple and natural syntax and provide formatted and colored output. Under favour of its programmable structure, it can perform many tasks at the same time. For example, you can pull data for user IDs 0, 1, and 2 at the same time

httpy in action

Features

Installation

$ pip3 install httpy-cli

Usage

Simple get request:

httpy httpbin.org/get

Synopsis:

$ httpy <URL> <METHOD> <HEADERS,QUERIES,DATA> --exec <COMMAND> <ARGS>

We will use api.service.com as a API server for simulating requests.

Let’s start with a simple request:

$ httpy api.service.com/users

This command will return all user objects. But if we want get only users with id 0, 1, 2, 3. Normally we have to do like this:

$ httpy api.service.com/users/0
  ...
$ httpy api.service.com/users/1
  ...
$ httpy api.service.com/users/2
  ...
$ httpy api.service.com/users/3
  ...

But we can do this in one line with httpy:

$ httpy 'api.service.com/users/{i}' -X i:0,1,2

This will be return all response for these ids.

i is arg name and it can be everything. And -X argument execute commands.

Variable name must be same with inside of {}. We can use {i} in everything. Headers, query values etc.

We can more simply the command:

$ httpy 'api.service.com/users/{i}' -X i:++:4

This command increment the variable each time.

The command syntax must be like this:

<VALUE>:<OPERATION>:<MAX_RUN>

We can use different operation:

Operation Description
++ Increment
-- Decrement
rand(0,10) Random number from 1 to 10
read(path/to/file) Read lines from file
item1,item2 List
item Text

For exaple we can get random number and use in request:

$ httpy 'api.service.com/users/{i}' -X 'i:rand(1,10)'

or we can use file as a token list for deleting users:

$ httpy 'api.service.com/users/me' DELETE 'Authorization:{i}' -X 'i:read(tokens.txt)'

or we can fill db with random 100 data in one line (we will see only status with -S):

$ httpy 'api.service.com/books' POST 'id={i}' 'title=Book {i}' -X 'i:rand(1,3000):100' -S

We can get only body with -B argument.

$ httpy 'api.service.com/users/{i}' -X i:3,4,5 -B

We can use other arguments for choosing what will see:

Argument Description
-B, --body Only show body
-H, --header Only show headers
-S, --status Only show status

We can combine args. For example we can print only body and status with -B and -S:

$ httpy 'api.service.com/users/{i}' -X i:3,4,5 -B -S

That’s it. You can check project page for all “operations” and all usages.

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.

Sinan Kanidağlı © 2022