47
Scott Leberknight

httpie

Embed Size (px)

DESCRIPTION

These are slides from a "mini-talk" (~15 minutes) I recently gave on httpie.

Citation preview

Page 1: httpie

Scott Leberknight

Page 2: httpie

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

Page 3: httpie

"HTTPie is a command line HTTP client. Its goal is to make CLI

interaction with web services as human-friendly as possible."

- httpie.org

Page 4: httpie

Implemented in Python

Provides simple http command

Colorized, formatted output

Page 5: httpie
Page 6: httpie

pip install --upgrade httpie

Installation

or

easy_install httpie

or

yum install httpie

(etc.)

Page 7: httpie

Major Features

colorized output

output formatting

query/form parameters

security (auth, https)

headers

form file uploads

persistent sessions

supports all HTTP verbs

wget-style downloads

streamed responses

Page 8: httpie

Usage

http [flags] [METHOD] URL [REQUEST ITEMS]

Page 9: httpie

3 cool sites to test with:

requestb.in

example.org

httpbin.org

Page 10: httpie
Page 11: httpie
Page 12: httpie
Page 13: httpie

Let's try it...

Page 14: httpie

Hello World

http httpie.org

Page 15: httpie
Page 16: httpie

-v (verbose)

Page 17: httpie

Defaults...

method - GET

scheme - http://

data fields - JSON

Page 18: httpie

Request Headers

http requestb.in/vnm6qyvn \ Accept:application/json \ X-Test-Header:'Foo, Bar'

Name:Value

Page 19: httpie
Page 20: httpie

URL parametersname==value

http requestb.in/vnm6qyvn \ search=='curl vs. httpie' \ page==2

Page 21: httpie
Page 22: httpie

Data Fields (JSON)field=value

[email protected]

http requestb.in/vnm6qyvn \ search='curl vs. httpie' \ page=2

Page 23: httpie

...httpie will set the method to POST

when a request contains data fields...

Page 24: httpie
Page 25: httpie

Data Fields (from a file)

http requestb.in/vnm6qyvn \ data=@/Users/sleberkn/w.txt

Page 26: httpie
Page 27: httpie

Data Fields (form)-f, --form

field=value

[email protected]

http --form requestb.in/vnm6qyvn \ search='curl vs. httpie' \ page=2

Page 28: httpie

...httpie will set the content type to application/x-www-form-urlencoded

when you use --form ( or -f )...

Page 29: httpie
Page 30: httpie

Raw JSONfield:=value

field:[email protected]

http requestb.in/vnm6qyvn \ terms:='["curl", "vs.", "httpie"]' \ page:=2

Page 31: httpie
Page 32: httpie

File Uploadsfield@/dir/file_name

http requestb.in/vnm6qyvn \ the_file@/Users/sleberkn/w.txt

Page 33: httpie

...httpie will set the content type to multipart/form-data

when you do a file upload...

Page 34: httpie
Page 35: httpie

Easy as httpie!

Page 36: httpie

HTTP Methods

GET

POST

PUT

PATCH

DELETE

HEAD

(and a few more obscure ones...)

Page 37: httpie

Testing methods with httpbin.org

http GET httpbin.org/get

http POST httpbin.org/post foo=bar

http PUT httpbin.org/put foo=bar

http PATCH httpbin.org/patch foo=bar

http -f DELETE httpbin.org/delete

Page 38: httpie

Authentication

BASIC (default) or Digest

-a,--auth

--auth-type

Has plugins for OAuth & others

Page 39: httpie

Username & password

Page 40: httpie

Username & password prompt

Page 41: httpie

Downloads-d,--download

-o,--output

http -d -o out.txt httpbin.org/get

Page 42: httpie
Page 43: httpie

Persistent Sessions

Custom headers, authorization, and cookies persist between requests to the same host

Named & anonymous sessions

Page 44: httpie

http --session=user1 \ -a user1:secret \ example.org \ X-Thingy:Foo

http --session=user2 \ -a user2:monkey \ example.org

Named Sessions

Page 45: httpie

Other stuff...

HTTPS support

Supports proxies

Redirect to/from http

Control output via flags (--headers, --body, --print, etc.)

JSON config file

Scripting support (via --check-status)

Streaming responses

Page 46: httpie

httpie web site: httpie.org (redirects to https://github.com/jkbr/httpie )

References

httpbin HTTP request & response service: httpbin.org

RequestBin: requestb.in

Page 47: httpie

My Info

twitter: sleberknight

www.sleberknight.com/blog

scott dot leberknight at gmail.com