Package: readme-test
HTTPie (pronouncedaitch-tee-tee-pie) is a command line HTTP client.
Its goal is to make CLI interaction with web services as human-friendly
as possible. It provides a simplehttpcommand that allows for sending
arbitrary HTTP requests using a simple and natural syntax, and displays
colorized output. HTTPie can be used for testing, debugging, and
generally interacting with HTTP servers.Contents1Main features2Installation2.1macOS2.2Linux2.3Windows, etc.2.4Development version2.5Python version3Usage3.1Examples4HTTP method5Request URL5.1Querystring parameters5.2URL shortcuts forlocalhost5.3Custom default scheme6Request items6.1Escaping rules7JSON7.1Default behaviour7.2Explicit JSON7.3Non-string JSON fields8Forms8.1Regular forms8.2File upload forms9HTTP headers9.1Default request headers9.2Empty headers and header un-setting10Authentication10.1Basic auth10.2Digest auth10.3Password prompt10.4.netrc10.5Auth plugins11HTTP redirects11.1FollowLocation11.2Showing intermediary redirect responses11.3Limiting maximum redirects followed12Proxies12.1Environment variables12.2SOCKS13HTTPS13.1Server SSL certificate verification13.2Custom CA bundle13.3Client side SSL certificate13.4SSL version13.5SNI (Server Name Indication)14Output options14.1What parts of the HTTP exchange should be printed14.2Viewing intermediary requests/responses14.3Conditional body download15Redirected Input15.1Request data from a filename16Terminal output16.1Colors and formatting16.2Binary data17Redirected output18Download mode18.1Downloaded file name18.2Piping while downloading18.3Resuming downloads18.4Other notes19Streamed responses19.1Disabling buffering19.2Examples use cases20Sessions20.1Named sessions20.2Anonymous sessions20.3Readonly session21Config21.1Config file location21.2Configurable options21.2.1default_options21.2.2__meta__21.3Un-setting previously specified options22Scripting22.1Best practices23Meta23.1Interface design23.2User support23.3Related projects23.3.1Dependencies23.3.2HTTPie friends23.4Contributing23.5Change log23.6Artwork23.7Licence23.8Authors1Main featuresExpressive and intuitive syntaxFormatted and colorized terminal outputBuilt-in JSON supportForms and file uploadsHTTPS, proxies, and authenticationArbitrary request dataCustom headersPersistent sessionsWget-like downloadsPython 2.6, 2.7 and 3.x supportLinux, Mac OS X and Windows supportPluginsDocumentationTest coverage2Installation2.1macOSOn macOS, HTTPie can be installed viaHomebrew(recommended):$brewinstallhttpieA MacPortsportis also available:$portinstallhttpie2.2LinuxMost Linux distributions provide a package that can be installed using the
system package manager, e.g.:# Debian-based distributions such as Ubuntu:$apt-getinstallhttpie# RPM-based distributions:$yuminstallhttpie# Arch Linux$pacman-Shttpie2.3Windows, etc.A universal installation method (that works on Windows, Mac OS X, Linux, …,
and always provides the latest version) is to usepip:# Make sure we have an up-to-date version of pip and setuptools:$pipinstall--upgradepipsetuptools$pipinstall--upgradehttpie(Ifpipinstallation fails for some reason, you can tryeasy_install httpieas a fallback.)2.4Development versionThe latest development version can be installed directly from GitHub:# Mac OS X via Homebrew$brewinstallhttpie--HEAD# Universal$pipinstall--upgradehttps://github.com/jkbrzt/httpie/archive/master.tar.gz2.5Python versionAlthough Python 2.6 and 2.7 are supported as well, it is recommended to install
HTTPie against the latest Python 3.x whenever possible. That will ensure that
some of the newer HTTP features, such asSNI (Server Name Indication),
work out of the box.
Python 3 is the default for Homebrew installations starting with version 0.9.4.
To see which version HTTPie uses, runhttp--debug.3UsageHello World:$httphttpie.orgSynopsis:$http[flags][METHOD]URL[ITEM[ITEM]]See alsohttp--help.3.1ExamplesCustomHTTP method,HTTP headersandJSONdata:$httpPUTexample.orgX-API-Token:123name=JohnSubmittingforms:$http-fPOSTexample.orghello=WorldSee the request that is being sent using one of theoutput options:$http-vexample.orgUseGithub APIto post a comment on anissuewithauthentication:$http-aUSERNAMEPOSThttps://api.github.com/repos/jkbrzt/httpie/issues/83/commentsbody='HTTPie is awesome! :heart:'Upload a file usingredirected input:$httpexample.org<file.jsonDownload a file and save it viaredirected output:$httpexample.org/file>fileDownload a filewgetstyle:$http--downloadexample.org/fileUse namedsessionsto make certain aspects or the communication persistent
between requests to the same host:$http--session=logged-in-ausername:passwordhttpbin.org/getAPI-Key:123$http--session=logged-inhttpbin.org/headersSet a customHostheader to work around missing DNS records:$httplocalhost:8000Host:example.com4HTTP methodThe name of the HTTP method comes right before the URL argument:$httpDELETEexample.org/todos/7Which looks similar to the actualRequest-Linethat is sent:DELETE/todos/7HTTP/1.1When theMETHODargument is omitted from the command, HTTPie defaults to
eitherGET(with no request data) orPOST(with request data).5Request URLThe only information HTTPie needs to perform a request is a URL.
The default scheme is, somewhat unsurprisingly,http://,
and can be omitted from the argument –http example.orgworks just fine.5.1Querystring parametersIf you find yourself manually constructing URLs with
on the terminal, you may appreciate theparam==valuesyntax for appending
URL parameters. With that, you don’t have to worry about escaping the&separators for your shell. Also, special characters in parameter values,
will also automatically escaped (HTTPie otherwise expects the URL to be
already escaped). To search forHTTPie logoon Google Images you could use
this command:$httpwww.google.comsearch=='HTTPie logo'tbm==ischGET/?search=HTTPie+logo&tbm=ischHTTP/1.15.2URL shortcuts forlocalhostAdditionally, curl-like shorthand for localhost is supported.
This means that, for example:3000would expand tohttp://localhost:3000If the port is omitted, then port 80 is assumed.$http:/fooGET/fooHTTP/1.1Host:localhost$http:3000/barGET/barHTTP/1.1Host:localhost:3000$http:GET/HTTP/1.1Host:localhost5.3Custom default schemeYou can use the--default-scheme<URL_SCHEME>option to create
shortcuts for other protocols than HTTP:$aliashttps='http --default-scheme=https'6Request itemsThere are a few differentrequest itemtypes that provide a
convenient mechanism for specifying HTTP headers, simple JSON and
form data, files, and URL parameters.They are key/value pairs specified after the URL. All have in
common that they become part of the actual request that is sent and that
their type is distinguished only by the separator used::,=,:=,==,@,=@, and:=@. The ones with an@expect a file path as value.Item TypeDescriptionHTTP HeadersName:ValueArbitrary HTTP header, e.g.X-API-Token:123.URL parametersname==valueAppends the given name/value pair as a query
string parameter to the URL.
The==separator is used.Data Fieldsfield=value,field=@file.txtRequest data fields to be serialized as a JSON
object (default), or to be form-encoded
(--form,-f).Raw JSON fieldsfield:=json,field:=@file.jsonUseful when sending JSON and one or
more fields need to be aBoolean,Number,
nestedObject, or anArray,  e.g.,meals:='["ham","spam"]'orpies:=[1,2,3](note the quotes).Form File Fieldsfield@/dir/fileOnly available with--form,-f.
For examplescreenshot@~/Pictures/img.png.
The presence of a file field results
in amultipart/form-datarequest.Note that data fields aren’t the only way to specify request data:Redirected inputis a mechanism for passing arbitrary data request
request.6.1Escaping rulesYou can use\to escape characters that shouldn’t be used as separators
(or parts thereof). For instance,foo\==barwill become a data key/value
pair (foo=andbar) instead of a URL parameter.Often it is necessary to quote the values, e.g.foo='barbaz'.If any of the field names or headers starts with a minus
(e.g.,-fieldname), you need to place all such items after the special
token--to prevent confusion with--arguments:$httphttpbin.org/post---name-starting-with-dash=foo-Unusual-Header:barPOST/postHTTP/1.1-Unusual-Header:barContent-Type:application/json{"-name-starting-with-dash":"value"}7JSONJSON is thelingua francaof modern web services and it is also theimplicit content typeHTTPie by default uses.Simple example:$httpPUTexample.orgname=Johnemail=john@example.orgPUT/HTTP/1.1Accept:application/json, */*Accept-Encoding:gzip, deflateContent-Type:application/jsonHost:example.org{"name":"John","email":"john@example.org"}7.1Default behaviourIf your command includes some datarequest items, they are serialized as a JSON
object by default. HTTPie also automatically sets the following headers,
both of which can be overwritten:Content-Typeapplication/jsonAcceptapplication/json, */*7.2Explicit JSONYou can use--json,-jto explicitly setAccepttoapplication/jsonregardless of whether you are sending data
(it’s a shortcut for setting the header via the usual header notation:http urlAccept:'application/json,*/*'). Additionally,
HTTPie will try to detect JSON responses even when theContent-Typeis incorrectlytext/plainor unknown.7.3Non-string JSON fieldsNon-string fields use the:=separator, which allows you to embed raw JSON
into the resulting object. Text and raw JSON files can also be embedded into
fields using=@and:=@:$httpPUTapi.example.com/person/1\name=John\age:=29married:=falsehobbies:='["http", "pies"]'\# Raw JSONdescription=@about-john.txt\# Embed text filebookmarks:=@bookmarks.json# Embed JSON filePUT/person/1HTTP/1.1Accept:application/json, */*Content-Type:application/jsonHost:api.example.com{"age":29,"hobbies":["http","pies"],"description":"John is a nice guy who likes pies.","married":false,"name":"John","bookmarks":{"HTTPie":"http://httpie.org",}}Please note that with this syntax the command gets unwieldy when sending
complex data. In that case it’s always better to useredirected input:$httpPOSTapi.example.com/person/1<person.json8FormsSubmitting forms is very similar to sendingJSONrequests. Often the only
difference is in adding the--form,-foption, which ensures that
data fields are serialized as, andContent-Typeis set to,application/x-www-form-urlencoded;charset=utf-8. It is possible to make
form data the implicit content type instead of JSON
via theconfigfile.8.1Regular forms$http--formPOSTapi.example.org/person/1name='John Smith'POST/person/1HTTP/1.1Content-Type:application/x-www-form-urlencoded; charset=utf-8name=John+Smith8.2File upload formsIf one or more file fields is present, the serialization and content type ismultipart/form-data:$http-fPOSTexample.com/jobsname='John Smith'cv@~/Documents/cv.pdfThe request above is the same as if the following HTML form were
submitted:<formenctype="multipart/form-data"method="post"action="http://example.com/jobs"><inputtype="text"name="name"/><inputtype="file"name="cv"/></form>Note that@is used to simulate a file upload form field, whereas=@just embeds the file content as a regular text field value.9HTTP headersTo set custom headers you can use theHeader:Valuenotation:$httpexample.orgUser-Agent:Bacon/1.0'Cookie:valued-visitor=yes;foo=bar'\X-Foo:BarReferer:http://httpie.org/GET/HTTP/1.1Accept:*/*Accept-Encoding:gzip, deflateCookie:valued-visitor=yes;foo=barHost:example.orgReferer:http://httpie.org/User-Agent:Bacon/1.0X-Foo:Bar9.1Default request headersThere are a couple of default headers that HTTPie sets:GET/HTTP/1.1Accept:*/*Accept-Encoding:gzip, deflateUser-Agent:HTTPie/<version>Host:<taken-from-URL>Any of those—except forHost—can be overwritten and some of them unset.9.2Empty headers and header un-settingTo unset a previously specified header
(such a one of the default headers), useHeader::$httphttpbin.org/headersAccept:User-Agent:To send a header with an empty value, useHeader;:$httphttpbin.org/headers'Header;'10AuthenticationThe currently supported authentication schemes are Basic and Digest
(seeauth pluginsfor more). There are two flags that control authentication:--auth,-aPass ausername:passwordpair as
the argument. Or, if you only specify a username
(-ausername), you’ll be prompted for
the password before the request is sent.
To send an empty password, passusername:.
Theusername:password@hostnameURL syntax is
supported as well (but credentials passed via-ahave higher priority).--auth-type,-ASpecify the auth mechanism. Possible values arebasicanddigest. The default value isbasicso it can often be omitted.10.1Basic auth$http-ausername:passwordexample.org10.2Digest auth$http-Adigest-ausername:passwordexample.org10.3Password prompt$http-ausernameexample.org10.4.netrcAuthorization information from your~/.netrcfile is honored as well:$cat~/.netrcmachinehttpbin.orgloginhttpiepasswordtest$httphttpbin.org/basic-auth/httpie/testHTTP/1.1200OK[...]10.5Auth pluginsAdditional authentication mechanism can be installed as plugins.
They can be found on thePython Package Index.
Here’s a few picks:httpie-api-auth: ApiAuthhttpie-aws-auth: AWS / Amazon S3httpie-edgegrid: EdgeGridhttpie-hmac-auth: HMAChttpie-jwt-auth: JWTAuth (JSON Web Tokens)httpie-negotiate: SPNEGO (GSS Negotiate)httpie-ntlm: NTLM (NT LAN Manager)httpie-oauth: OAuthrequests-hawk: Hawk11HTTP redirectsBy default, HTTP redirects are not followed and only the first
response is shown:$httphttpbin.org/redirect/311.1FollowLocationTo instruct HTTPie to follow theLocationheader of30xresponses
and show the final response instead, use the--follow,-Foption:$http--followhttpbin.org/redirect/311.2Showing intermediary redirect responsesIf you additionally wish to see the intermediary requests/responses,
then use the--alloption as well:$http--follow--allhttpbin.org/redirect/311.3Limiting maximum redirects followedTo change the default limit of maximum30redirects, use the--max-redirects=<limit>option:$http--follow--all--max-redirects=5httpbin.org/redirect/312ProxiesYou can specify proxies to be used through the--proxyargument for each
protocol (which is included in the value in case of redirects across protocols):$http--proxy=http:http://10.10.1.10:3128--proxy=https:https://10.10.1.10:1080example.orgWith Basic authentication:$http--proxy=http:http://user:pass@10.10.1.10:3128example.org12.1Environment variablesYou can also configure proxies by environment variablesHTTP_PROXYandHTTPS_PROXY, and the underlying Requests library will pick them up as well.
If you want to disable proxies configured through the environment variables for
certain hosts, you can specify them inNO_PROXY.In your~/.bash_profile:exportHTTP_PROXY=http://10.10.1.10:3128exportHTTPS_PROXY=https://10.10.1.10:1080exportNO_PROXY=localhost,example.com12.2SOCKSTo enable SOCKS proxy support please installrequests[socks]usingpip:$pipinstall-Urequests[socks]Usage is the same as for other types ofproxies:$http--proxy=http:socks5://user:pass@host:port--proxy=https:socks5://user:pass@host:portexample.org13HTTPS13.1Server SSL certificate verificationTo skip the host’s SSL certificate verification, you can pass--verify=no(default isyes):$http--verify=nohttps://example.org13.2Custom CA bundleYou can also use--verify=<CA_BUNDLE_PATH>to set a custom CA bundle path:$http--verify=/ssl/custom_ca_bundlehttps://example.org13.3Client side SSL certificateTo use a client side certificate for the SSL communication, you can pass
the path of the cert file with--cert:$http--cert=client.pemhttps://example.orgIf the private key is not contained in the cert file you may pass the
path of the key file with--cert-key:$http--cert=client.crt--cert-key=client.keyhttps://example.org13.4SSL versionUse the--ssl=<PROTOCOL>to specify the desired protocol version to use.
This will default to SSL v2.3 which will negotiate the highest protocol that both
the server and your installation of OpenSSL support. The available protocols
aressl2.3,ssl3,tls1,tls1.1,tls1.2. (The actually
available set of protocols may vary depending on your OpenSSL installation.)# Specify the vulnerable SSL v3 protocol to talk to an outdated server:$http--ssl=ssl3https://vulnerable.example.org13.5SNI (Server Name Indication)If you use HTTPie withPython versionlower than 2.7.9
(can be verified withhttp--debug) and need to talk to servers that
use SNI (Server Name Indication) you need to install some additional
dependencies:$pipinstall--upgraderequests[security]You can use the following command to test SNI support:$httphttps://sni.velox.ch14Output optionsBy default, HTTPie only outputs the final response and the whole response
message is printed (headers as well as the body). You can control what should
be printed via several options:--headers,-hOnly the response headers are printed.--body,-bOnly the response body is printed.--verbose,-vPrint the whole HTTP exchange (request and response).
This option also enables--all(see bellow).--print,-pSelects parts of the HTTP exchange.--verbosecan often be useful for debugging the request and generating
documentation examples:$http--verbosePUThttpbin.org/puthello=worldPUT/putHTTP/1.1Accept:application/json,*/*Accept-Encoding:gzip,deflateContent-Type:application/jsonHost:httpbin.orgUser-Agent:HTTPie/0.2.7dev{"hello":"world"}HTTP/1.1200OKConnection:keep-aliveContent-Length:477Content-Type:application/jsonDate:Sun,05Aug201200:25:23GMTServer:gunicorn/0.13.4{[…]}14.1What parts of the HTTP exchange should be printedAll the otheroutput optionsare under the hood just shortcuts for
the more powerful--print,-p. It accepts a string of characters each
of which represents a specific part of the HTTP exchange:CharacterStands forHrequest headersBrequest bodyhresponse headersbresponse bodyPrint request and response headers:$http--print=HhPUThttpbin.org/puthello=world14.2Viewing intermediary requests/responsesTo see all the HTTP communication, i.e. the final request/response as
well as any possible  intermediary requests/responses, use the--alloption. The intermediary HTTP communication include followed redirects
(with--follow), the first unauthorized request when HTTP digest
authentication is used (--auth=digest), etc.# Include all responses that lead to the final one:$http--all--followhttpbin.org/redirect/3The intermediary requests/response are by default formatted according to--print,-p(and its shortcuts described above). If you’d like to change
that, use the--history-print,-Poption. It takes the same
arguments as--print,-pbut applies to the intermediary requests only.# Print the intermediary requests/responses differently than the final one:$http-Adigest-afoo:bar--all-pHh-PHhttpbin.org/digest-auth/auth/foo/bar14.3Conditional body downloadAs an optimization, the response body is downloaded from the server
only if it’s part of the output. This is similar to performing aHEADrequest, except that it applies to any HTTP method you use.Let’s say that there is an API that returns the whole resource when it is
updated, but you are only interested in the response headers to see the
status code after an update:$http--headersPATCHexample.org/Really-Huge-Resourcename='New Name'Since we are only printing the HTTP headers here, the connection to the server
is closed as soon as all the response headers have been received.
Therefore, bandwidth and time isn’t wasted downloading the body
which you don’t care about. The response headers are downloaded always,
even if they are not part of the output15Redirected InputThe universal method for passing request data is through redirectedstdin(standard input)—piping. Such data is buffered and then with no further
processing used as the request body. There are multiple useful ways to use
piping:Redirect from a file:$httpPUTexample.com/person/1X-API-Token:123<person.jsonOr the output of another program:$grep'401 Unauthorized'/var/log/httpd/error_log|httpPOSTexample.org/intrudersYou can useechofor simple data:$echo'{"name": "John"}'|httpPATCHexample.com/person/1X-API-Token:123You can even pipe web services together using HTTPie:$httpGEThttps://api.github.com/repos/jkbrzt/httpie|httpPOSThttpbin.org/postYou can usecatto enter multiline data on the terminal:$cat|httpPOSTexample.com<paste>^D$cat|httpPOSTexample.com/todosContent-Type:text/plain-buymilk-callparents^DOn OS X, you can send the contents of the clipboard withpbpaste:$pbpaste|httpPUTexample.comPassing data throughstdincannot be combined with data fields specified
on the command line:$echo'data'|httpPOSTexample.orgmore=data# This is invalidTo prevent HTTPie from readingstdindata you can use the--ignore-stdinoption.15.1Request data from a filenameAn alternative to redirectedstdinis specifying a filename (as@/path/to/file) whose content is used as if it came fromstdin.It has the advantage that theContent-Typeheader is automatically set to the appropriate value based on the
filename extension. For example, the following request sends the
verbatim contents of that XML file withContent-Type:application/xml:$httpPUThttpbin.org/put@/data/file.xml16Terminal outputHTTPie does several things by default in order to make its terminal output
easy to read.16.1Colors and formattingSyntax highlighting is applied to HTTP headers and bodies (where it makes
sense). You can choose your preferred color scheme via the--styleoption
if you don’t like the default one (see$ http--helpfor the possible
values).Also, the following formatting is applied:HTTP headers are sorted by name.JSON data is indented, sorted by keys, and unicode escapes are converted
to the characters they represent.One of these options can be used to control output processing:--pretty=allApply both colors and formatting.
Default for terminal output.--pretty=colorsApply colors.--pretty=formatApply formatting.--pretty=noneDisables output processing.
Default for redirected output.16.2Binary dataBinary data is suppressed for terminal output, which makes it safe to perform
requests to URLs that send back binary data. Binary data is suppressed also in
redirected, but prettified output. The connection is closed as soon as we know
that the response body is binary,$httpexample.org/Movie.movYou will nearly instantly see something like this:HTTP/1.1200OKAccept-Ranges:bytesContent-Encoding:gzipContent-Type:video/quicktimeTransfer-Encoding:chunked+-----------------------------------------+
| NOTE: binary data not shown in terminal |
+-----------------------------------------+17Redirected outputHTTPie uses a different set of defaults for redirected output than forterminal output. The differences being:Formatting and colors aren’t applied (unless--prettyis specified).Only the response body is printed (unless one of theoutput optionsis set).Also, binary data isn’t suppressed.The reason is to make piping HTTPie’s output to another programs and
downloading files work with no extra flags. Most of the time, only the raw
response body is of an interest when the output is redirected.Download a file:$httpexample.org/Movie.mov>Movie.movDownload an image of Octocat, resize it using ImageMagick, upload it elsewhere:$httpoctodex.github.com/images/original.jpg|convert--resize25%-|httpexample.org/OctocatsForce colorizing and formatting, and show both the request and the response inlesspager:$http--pretty=all--verboseexample.org|less-RThe-Rflag tellslessto interpret color escape sequences included
HTTPie`s output.You can create a shortcut for invoking HTTPie with colorized and paged output
by adding the following to your~/.bash_profile:functionhttpless{# `httpless example.org'http--pretty=all--print=hb"$@"|less-R;}18Download modeHTTPie features a download mode in which it acts similarly towget.When enabled using the--download,-dflag, response headers are printed to
the terminal (stderr), and a progress bar is shown while the response body
is being saved to a file.$http--downloadhttps://github.com/jkbrzt/httpie/archive/master.tar.gzHTTP/1.1200OKContent-Disposition:attachment; filename=httpie-master.tar.gzContent-Length:257336Content-Type:application/x-gzipDownloading 251.30 kB to "httpie-master.tar.gz"
Done. 251.30 kB in 2.73862s (91.76 kB/s)18.1Downloaded file nameIf not provided via--output,-o, the output filename will be determined
fromContent-Disposition(if available), or from the URL andContent-Type. If the guessed filename already exists, HTTPie adds a unique
suffix to it.18.2Piping while downloadingYou can also redirect the response body to another program while the response
headers and progress are still shown in the terminal:$http-dhttps://github.com/jkbrzt/httpie/archive/master.tar.gz|tarzxf-18.3Resuming downloadsIf--output,-ois specified, you can resume a partial download using the--continue,-coption. This only works with servers that supportRangerequests and206 Partial Contentresponses. If the server doesn’t
support that, the whole file will simply be downloaded:$http-dcofile.zipexample.org/file18.4Other notesThe--downloadoption only changes how the response body is treated.You can still set custom headers, use sessions,--verbose,-v, etc.--downloadalways implies--follow(redirects are followed).HTTPie exits with status code1(error) if the body hasn’t been fully
downloaded.Accept-Encodingcannot be set with--download.19Streamed responsesResponses are downloaded and printed in chunks which allows for streaming
and large file downloads without using too much memory. However, whencolors and formattingis applied, the whole response is buffered and only
then processed at once.19.1Disabling bufferingYou can use the--stream,-Sflag to make two things happen:The output is flushed in much smaller chunks without any buffering,
which makes HTTPie behave kind of liketail-ffor URLs.Streaming becomes enabled even when the output is prettified: It will be
applied to each line of the response and flushed immediately. This makes
it possible to have a nice output for long-lived requests, such as one
to the Twitter streaming API.19.2Examples use casesPrettified streamed response:$http--stream-f-aYOUR-TWITTER-NAMEhttps://stream.twitter.com/1/statuses/filter.jsontrack='Justin Bieber'Streamed output by small chunks alátail-f:# Send each new tweet (JSON object) mentioning "Apple" to another
# server as soon as it arrives from the Twitter streaming API:$http--stream-f-aYOUR-TWITTER-NAMEhttps://stream.twitter.com/1/statuses/filter.jsontrack=Apple\|whilereadtweet;doecho"$tweet"|httpPOSTexample.org/tweets;done20SessionsBy default, every request HTTPie makes is completely independent of any
previous ones to the same host.However, HTTPie also supports persistent
sessions via the--session=SESSION_NAME_OR_PATHoption. In a session,
custom headers—except for the ones starting withContent-orIf-—,
authorization, and cookies
(manually specified or sent by the server) persist between requests
to the same host.# Create a new session$http--session=/tmp/session.jsonexample.orgAPI-Token:123# Re-use an existing session — API-Token will be set:$http--session=/tmp/session.jsonexample.orgAll session data, including credentials, cookie data,
and custom headers are stored in plain text.
That means session files can also be created and edited manually in a text
editor—they are regular JSON.20.1Named sessionsYou can create one or more named session per host. For example, this is how
you can create a new session nameduser1forexample.org:$http--session=user1-auser1:passwordexample.orgX-Foo:BarFrom now onw, you can refer to the session by its name. When you choose to
use the session again, any the previously used authorization and HTTP headers
will automatically be set:$http--session=user1example.orgTo create or reuse a different session, simple specify a different name:$http--session=user2-auser2:passwordexample.orgX-Bar:FooNamed sessions’ data is stored in JSON files in the directory~/.httpie/sessions/<host>/<name>.json(%APPDATA%\httpie\sessions\<host>\<name>.jsonon Windows).20.2Anonymous sessionsInstead of a name, you can also directly specify a path to a session file. This
allows for sessions to be re-used across multiple hosts:$http--session=/tmp/session.jsonexample.org$http--session=/tmp/session.jsonadmin.example.org$http--session=~/.httpie/sessions/another.example.org/test.jsonexample.org$http--session-read-only=/tmp/session.jsonexample.org20.3Readonly sessionTo use an existing session file without updating it from the request/response
exchange once it is created, specify the session name via--session-read-only=SESSION_NAME_OR_PATHinstead.21ConfigHTTPie uses a simple JSON config file.21.1Config file locationThe default location of the configuration file is~/.httpie/config.json(or%APPDATA%\httpie\config.jsonon Windows). The config directory
location can be changed by setting theHTTPIE_CONFIG_DIRenvironment variable. To view the exact location runhttp--debug.21.2Configurable optionsThe JSON file contains an object with the following keys:21.2.1default_optionsAnArray(by default empty) of default options that should be applied to
every invocation of HTTPie.For instance, you can use this option to change the default style and output
options:"default_options":["--style=fruity","--body"]Another useful
default option could be"--session=default"to make HTTPie always
usesessions(one nameddefaultwill automatically be used).
Or you could change the implicit request content type from JSON to form by
adding--formto the list.21.2.2__meta__HTTPie automatically stores some of its metadata here. Please do not change.21.3Un-setting previously specified optionsDefault options from the config file, or specified any other way,
can be unset for a particular invocation via--no-OPTIONarguments passed
on the command line (e.g.,--no-styleor--no-session).22ScriptingWhen using HTTPie from shell scripts, it can be handy to set the--check-statusflag. It instructs HTTPie to exit with an error if the
HTTP status is one of3xx,4xx, or5xx. The exit status will
be3(unless--followis set),4, or5,
respectively.#!/bin/bashifhttp--check-status--ignore-stdin--timeout=2.5HEADexample.org/health&>/dev/null;thenecho'OK!'elsecase$?in2)echo'Request timed out!';;3)echo'Unexpected HTTP 3xx Redirection!';;4)echo'HTTP 4xx Client Error!';;5)echo'HTTP 5xx Server Error!';;6)echo'Exceeded --max-redirects=<n> redirects!';;*)echo'Other Error!';;esacfi22.1Best practicesThe default behaviour of automatically readingstdinis typically not
desirable during non-interactive invocations. You most likely want
use the--ignore-stdinoption to disable it.It is a common gotcha that without this option HTTPie seemingly hangs.
What happens is that when HTTPie is invoked for example from a cron job,stdinis not connected to a terminal.
Therefore, rules forredirected inputapply, i.e., HTTPie starts to read it
expecting that the request body will be passed through.
And since there’s no data norEOF, it will be stuck. So unless you’re
piping some data to HTTPie, this flag should be used in scripts.Also, it’s might be good to override the default30second--timeoutto
something that suits you.23Meta23.1Interface designThe 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. It is often possible to translate an HTTP request to an HTTPie
argument list just by inlining the request elements. For example, compare this
HTTP request:POST/collectionHTTP/1.1X-API-Key:123User-Agent:Bacon/1.0Content-Type:application/x-www-form-urlencodedname=value&name2=value2with the HTTPie command that sends it:$http-fPOSTexample.org/collection\X-API-Key:123\User-Agent:Bacon/1.0\name=value\name2=value2Notice that both the order of elements and the syntax is very similar,
and that only a small portion of the command is used to control HTTPie and
doesn’t directly correspond to any part of the request (here it’s only-fasking HTTPie to send a form request).The two modes,--pretty=all(default for terminal) and--pretty=none(default for redirected output), allow for both user-friendly interactive use
and usage from scripts, where HTTPie serves as a generic HTTP client.As HTTPie is still under heavy development, the existing command line
syntax and some of the--OPTIONSmay change slightly before
HTTPie reaches its final version1.0. All changes are recorded in thechange log.23.2User supportPlease use the following support channels:GitHub issuesfor bug reports and feature requests.Our Gitter chat roomto ask questions, discuss features, and for general discussion.StackOverflowto ask questions (please make sure to use thehttpietag).Tweet directly to@clihttp.You can also tweet directly to@jkbrzt.23.3Related projects23.3.1DependenciesUnder the hood, HTTPie uses these two amazing libraries:Requests— Python HTTP library for humansPygments— Python syntax highlighter23.3.2HTTPie friendsHTTPie plays exceptionally well with the following tools:jq— CLI JSON processor that
works great in conjunction with HTTPiehttp-prompt—  interactive shell for HTTPie featuring autocomplete
and command syntax highlighting23.4ContributingSeeCONTRIBUTING.rst.23.5Change logSeeCHANGELOG.23.6ArtworkSeeclaudiatd/httpie-artwork23.7LicenceBSD-3-Clause:LICENSE.23.8AuthorsJakub Roztocil(@jkbrzt) created HTTPie andthese fine peoplehave contributed.