Post on 22-Jun-2015
description
transcript
Scott Leberknight
"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."
- httpie.org
Implemented in Python
Provides simple http command
Colorized, formatted output
pip install --upgrade httpie
Installation
or
easy_install httpie
or
yum install httpie
(etc.)
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
Usage
http [flags] [METHOD] URL [REQUEST ITEMS]
3 cool sites to test with:
requestb.in
example.org
httpbin.org
Let's try it...
Hello World
http httpie.org
-v (verbose)
Defaults...
method - GET
scheme - http://
data fields - JSON
Request Headers
http requestb.in/vnm6qyvn \ Accept:application/json \ X-Test-Header:'Foo, Bar'
Name:Value
URL parametersname==value
http requestb.in/vnm6qyvn \ search=='curl vs. httpie' \ page==2
Data Fields (JSON)field=value
field=@file.txt
http requestb.in/vnm6qyvn \ search='curl vs. httpie' \ page=2
...httpie will set the method to POST
when a request contains data fields...
Data Fields (from a file)
http requestb.in/vnm6qyvn \ data=@/Users/sleberkn/w.txt
Data Fields (form)-f, --form
field=value
field=@file.txt
http --form requestb.in/vnm6qyvn \ search='curl vs. httpie' \ page=2
...httpie will set the content type to application/x-www-form-urlencoded
when you use --form ( or -f )...
Raw JSONfield:=value
field:=@file.txt
http requestb.in/vnm6qyvn \ terms:='["curl", "vs.", "httpie"]' \ page:=2
File Uploadsfield@/dir/file_name
http requestb.in/vnm6qyvn \ the_file@/Users/sleberkn/w.txt
...httpie will set the content type to multipart/form-data
when you do a file upload...
Easy as httpie!
HTTP Methods
GET
POST
PUT
PATCH
DELETE
HEAD
(and a few more obscure ones...)
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
Authentication
BASIC (default) or Digest
-a,--auth
--auth-type
Has plugins for OAuth & others
Username & password
Username & password prompt
Downloads-d,--download
-o,--output
http -d -o out.txt httpbin.org/get
Persistent Sessions
Custom headers, authorization, and cookies persist between requests to the same host
Named & anonymous sessions
http --session=user1 \ -a user1:secret \ example.org \ X-Thingy:Foo
http --session=user2 \ -a user2:monkey \ example.org
Named Sessions
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
httpie web site: httpie.org (redirects to https://github.com/jkbr/httpie )
References
httpbin HTTP request & response service: httpbin.org
RequestBin: requestb.in
My Info
twitter: sleberknight
www.sleberknight.com/blog
scott dot leberknight at gmail.com