HTTPie

A CLI, cURL-like tool for humans

Theorem
Theorem
Sep 8, 2015 · 3 min read

by Emiliano Mancuso

This is another entry in our series of technical articles about software development tools and libraries. Today I would like to introduce you to HTTPie, an HTTP client which will help you to put aside cURL, that wonderful — but not so human-friendly — tool.

cURL is an open source command-line tool and library for transferring data with URL syntax, supporting an extensive protocol list. It is widely-used in development and system administration.

cURL is a powerful tool, but its syntax can be very confusing for the occasional user. I’ve used cURL sporadically over the last few years, and each time I began using it, I had to re-google “how to use cURL”. The syntax is not intuitive for me. If you like to use cURL occasionally, HTTPie will help you get started faster, and improve the readability of your code.

Back to HTTPie, it provides a simple http command — the client side of the HTTP/1.1 protocol — which allows us to send HTTP requests using a simple and natural syntax and returns colorized output. The package implements the GET, POST, and HEAD operations of HTTP/1.1.

Installation

OS X

Universal method

This will work on Windows, OS X, Linux, etc.

Usage

GET

PUT

POST

Adding the — form or -f option, HTTPie ensures that data fields are serialized as, and Content-Type is set to, application/x-www-form-urlencoded; charset=utf-8.

However, my favorite version is to use a file and redirect the input which is great for complex or nested JSON objects:

Request Items

Adding headers is as simple as specifying a key/value pair like Name:Value. If you want to add URL parameters, just use name==value, and for data fields field=value, which will be serialized as a JSON object by default.

A common curl command such as

Becomes

This tool does not provide us with anything new, but it enhances and simplifies the syntax we need to use when testing or interacting with HTTP servers. The syntax of the command arguments closely corresponds to the actual HTTP requests sent over the wire. It has the advantage that it’s easy to remember and read.

You should definitely try it and read the full documentation. I bet you will love the Sessions section as much as I did.


Originally published at bits.citrusbyte.com on August 19, 2015.

Theorem

We are an engineering and innovation firm.

Theorem

Written by

Theorem

Innovate like a startup even if you aren’t one

Theorem

Theorem

We are an engineering and innovation firm. We solve complex business problems through optimization of process, technology, and culture.

Theorem

Written by

Theorem

Innovate like a startup even if you aren’t one

Theorem

Theorem

We are an engineering and innovation firm. We solve complex business problems through optimization of process, technology, and culture.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store