Brandon Kang

Let's use 'HTTPie' instead of cURL

Blog Post created by Brandon Kang Employee on Jul 23, 2015

HTTPie: a CLI, cURL-like tool for humans - httpie.org -

 

HTTPie is a command line HTTP client. Its goal is to make CLI interaction with web services as human-friendly as possible.

It's implemented in Python. it provides very simple command 'http' - not 'httpie', so be careful.

It generate colorful response header and body so that we can figure out the kinds of results easily.

 

Examples)

1) When there are only response headers.

$ http GET www.akamai.com

HTTP/1.1 301 Moved Permanently

Connection: keep-alive

Content-Length: 0

Date: Thu, 23 Jul 2015 12:19:44 GMT

Location: https://www.akamai.com

Server: AkamaiGHost

 

2) Response headers and body (just a part.)

$ http GET https://www.akamai.com

HTTP/1.1 200 OK

Cache-Control: max-age=249

Connection: keep-alive

Connection: Transfer-Encoding

Content-Encoding: gzip

Content-Type: text/html;charset=UTF-8

Date: Thu, 23 Jul 2015 12:19:07 GMT

ETag: "0c6ec848b554b34c0cb98e0bfe8eb901a-gzip"

Server: Apache/2.4.7 (Ubuntu)

Transfer-Encoding:  chunked

Vary: Accept-Encoding

 

<!DOCTYPE html>

 

<html lang="en-US" class="no-js">

 

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1">

 

3) Plus, Akamai Pragma headers surely work well.

$ http www.akamai.com Pragma:'akamai-x-cache-on ....(skipped...)'

HTTP/1.1 301 Moved Permanently

Connection: keep-alive

Content-Length: 0

Date: Thu, 23 Jul 2015 12:28:47 GMT

Location: https://www.akamai.com

Server: AkamaiGHost

X-Akamai-Request-ID: 461272e

X-Akamai-Session-Info: name=AKA_PM_BASEDIR; value=

X-Akamai-Session-Info: name=AKA_PM_CACHEABLE_OBJECT; value=true

X-Akamai-Session-Info: name=AKA_PM_FWD_URL; value=/

 

4) Seeing JSON response after POST request is also enabled.

$ http POST httpbin.org/post var1=hello

HTTP/1.1 200 OK

Access-Control-Allow-Credentials: true

Access-Control-Allow-Origin: *

Connection: keep-alive

Content-Length: 415

Content-Type: application/json

Date: Thu, 23 Jul 2015 12:22:53 GMT

Server: nginx

 

{

    "args": {},

    "data": "{\"var1\": \"hello\"}",

    "files": {},

    "form": {},

    "headers": {

        "Accept": "application/json",

        "Accept-Encoding": "gzip, deflate",

        "Content-Length": "17",

        "Content-Type": "application/json",

        "Host": "httpbin.org",

        "User-Agent": "HTTPie/0.9.2"

    },

    "json": {

        "var1": "hello"

    },

    "origin": "61.43.139.4",

    "url": "http://httpbin.org/post


You can download/install httpie here: jkbrzt/httpie · GitHub

The more information to use this tool can be obtained here: http://www.slideshare.net/scottleber/htt-pie-minitalk

 

Akamai's {OPEN} API supports httpie as a client. my next article will be about it.

Thanks.

Outcomes