HTTPie for Performance Engineers
Tags: testing, tutorial, webperf, webdev
Published: 2021-09-08 15:13:14

<!-- wp:paragraph -->
<p>In this blog post we are going to learn HTTPie - a command line utility to debug web services. In our last post, we read about <a href="https://qainsights.com/curl-tips-for-performance-engineers/" target="_blank" rel="noreferrer noopener">cURL for Performance Engineers</a>. If you are looking for a cURL alternative, you can check out HTTPie.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>What is HTTPie?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Here is the excerpt from httpie.io:</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p><em>HTTPie (pronounced&nbsp;aitch-tee-tee-pie) is a command-line HTTP client. Its goal is to make CLI interaction with web services as human-friendly as possible. HTTPie is designed for testing, debugging, and generally interacting with APIs &amp; HTTP servers.</em></p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>It supports both http and https; displays it in color by default. </p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"d5babefb"} -->
<h2 class="gb-headline gb-headline-d5babefb gb-headline-text">How to install HTTPIe?</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>You can HTTPie on Linux, Windows and macOS. The only prerequisite is Python 3.6 or greater.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Head to https://httpie.io/docs#installation to see the instructions based on your OS.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this demonstration, we are going to utilize HTTPie on Windows Subsystem for Linux (WSL).</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Issue any one of the below command to install HTTPie.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo apt install httpie</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>or</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>python -m pip install --upgrade pip setuptools
python -m pip install --upgrade httpie</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>After successful installation, you can validate by issuing <code>http --version</code> or <code>https --version</code> which will display the installed version of httpie.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8661,"sizeSlug":"full","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2021/09/image-13.png"><img src="https://qainsights.com/wp-content/uploads/2021/09/image-13.png" alt="HTTPie for Performance Engineers" class="wp-image-8661"/></a><figcaption>HTTPie for Performance Engineers</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Throughout this demo, we are going to use <code>https</code> variant.</p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"c77b0901"} -->
<h2 class="gb-headline gb-headline-c77b0901 gb-headline-text">HTTPie Features</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:list -->
<ul><li>Expressive and intuitive syntax</li><li>Formatted and colorized terminal output</li><li>Built-in JSON support</li><li>Forms and file uploads</li><li>HTTPS, proxies, and authentication.</li><li>Arbitrary request data</li><li>Custom headers</li><li>Persistent sessions</li><li>Wget-like downloads</li><li>Linux, macOS and Windows support</li><li>Plugins</li><li>Documentation</li><li>Test coverage</li></ul>
<!-- /wp:list -->

<!-- wp:embed {"url":"https://youtu.be/EBHqAPp1PIw","type":"video","providerNameSlug":"youtube","responsive":true,"className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://youtu.be/EBHqAPp1PIw
</div></figure>
<!-- /wp:embed -->

<!-- wp:generateblocks/headline {"uniqueId":"6a2e8cc2"} -->
<h2 class="gb-headline gb-headline-6a2e8cc2 gb-headline-text">Usage</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:heading {"level":3} -->
<h3>Hello World</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Let us start with the simple <code>GET</code> method using the httpbin.org demo app. As you can see, by default, httpie will display the response and the headers in the colored format.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https httpbin.org/get</code></pre>
<!-- /wp:code -->

<!-- wp:image {"align":"center","id":8662,"sizeSlug":"full","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2021/09/image-14.png"><img src="https://qainsights.com/wp-content/uploads/2021/09/image-14.png" alt="" class="wp-image-8662"/></a><figcaption>HTTPie - Hello World</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:generateblocks/headline {"uniqueId":"159d3dd8","element":"h3"} -->
<h3 class="gb-headline gb-headline-159d3dd8 gb-headline-text">POST</h3>
<!-- /wp:generateblocks/headline -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https httpbin.org/post name=naveenkumar</code></pre>
<!-- /wp:code -->

<!-- wp:generateblocks/headline {"uniqueId":"bb43fad3","element":"h3"} -->
<h3 class="gb-headline gb-headline-bb43fad3 gb-headline-text">Submit Form</h3>
<!-- /wp:generateblocks/headline -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https -f httpbin.org/post custname=naveenkumar&amp;custtel=&amp;custemail=&amp;size=small&amp;topping=mushroom&amp;delivery=&amp;comments=</code></pre>
<!-- /wp:code -->

<!-- wp:generateblocks/headline {"uniqueId":"4054aeac","element":"h3"} -->
<h3 class="gb-headline gb-headline-4054aeac gb-headline-text">View the sent request</h3>
<!-- /wp:generateblocks/headline -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https -v httpbin.org/post name=naveenkumar</code></pre>
<!-- /wp:code -->

<!-- wp:generateblocks/headline {"uniqueId":"a051d102","element":"h3"} -->
<h3 class="gb-headline gb-headline-a051d102 gb-headline-text">Download File</h3>
<!-- /wp:generateblocks/headline -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https https://httpbin.org/image/png &gt; myimage.png</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3} -->
<h3>Upload File</h3>
<!-- /wp:heading -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https POST https://httpbin.org/post &lt; myimage.png</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3} -->
<h3>Follow Redirect</h3>
<!-- /wp:heading -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https --follow pie.dev/redirect/4</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3} -->
<h3>Proxy</h3>
<!-- /wp:heading -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https --proxy=http:http://localhost:3128 --proxy=https:https://localhost:1080 example.net</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3} -->
<h3>Skip HTTPS check</h3>
<!-- /wp:heading -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https --verify=no https://pie.dev/get</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3} -->
<h3>SSL Version</h3>
<!-- /wp:heading -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https --ssl=ssl3 https://example.org</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3} -->
<h3>View Headers</h3>
<!-- /wp:heading -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https httpbin.org/get -h</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3} -->
<h3>View Body</h3>
<!-- /wp:heading -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https httpbin.org/get -b</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3} -->
<h3>Stream</h3>
<!-- /wp:heading -->

<!-- wp:code -->
<pre class="wp-block-code"><code>http --stream httpbin.org/stream/3</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>I have listed only the frequently commands which I use for debugging. Apart from these, HTTPie supports named sessions, wget-like downloads, piping, formatting, resuming downloads, conditional body download, SOCKS, and more.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Here is the GitHub repo for your reference: https://github.com/httpie/httpie</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>HTTPie will be available for the web and desktop soon.</p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"d4c7c718"} -->
<h2 class="gb-headline gb-headline-d4c7c718 gb-headline-text">Conclusion</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>If you are looking to debug HTTP requests and for cURL alternative, then HTTPie is for you. Easy to learn and get started; comes with powerful features and format options.</p>
<!-- /wp:paragraph -->