HTTP Prompt for Performance Engineers
Tags: testing, tools, webperf, performance
Published: 2021-09-28 13:37:54

<!-- wp:paragraph -->
<p>In this blog post, we are going to see how you can get started with HTTP Prompt - an interactive command-line HTTP client for testing and debugging purpose. In the last couple of posts, I have covered <a href="https://qainsights.com/httpie-for-performance-engineers/" target="_blank" rel="noreferrer noopener">HTTPie </a>and <a href="https://qainsights.com/http-toolkit-for-performance-engineers/" target="_blank" rel="noreferrer noopener">HTTP Toolkit</a> utilities for performance testers and engineers. Let us get started by installing it.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>How to install HTTP Prompt?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The prerequisite is to have the latest version of Python and the PIP package. To install HTTP Prompt, I am going to use Windows Subsystem for Linux (WSL) and by issuing the below command. Alternatively, you can install it on the native OS as well.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>pip install http-prompt</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>P.S: using the <code>sudo</code> on <code>pip</code> is not recommended.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you would like to upgrade, issue the below command.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>pip install -U http-prompt</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>To validate the installation, issue the below command.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>http-prompt --version</code></pre>
<!-- /wp:code -->

<!-- wp:generateblocks/headline {"uniqueId":"3120a4c9"} -->
<h2 class="gb-headline gb-headline-3120a4c9 gb-headline-text">HTTP Prompt Features</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>HTTP Prompt has all the essential features for testing HTTP requests. But what is unique in HTTP Prompt is the following features: <strong>interactive, auto-complete and syntax highlighting</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Other features are:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Auto Cookies</li><li>OpenAPI/Swagger Integration</li><li>Unix-like Pipelines</li><li><a href="https://qainsights.com/httpie-for-performance-engineers/">HTTPie</a>&nbsp;compatible</li></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2>Hello World</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To start HTTP Prompt, open the command line prompt and issue the below command to start a session targetting https://example.com</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>http-prompt https://example.com</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>The above command creates a session where you can interact with it, e.g. issuing the below command displays the HTTP response. While typing the command, HTTP Prompt will autofill it for you.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8695,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image size-full"><a href="https://qainsights.com/wp-content/uploads/2021/09/supershot.png"><img src="https://qainsights.com/wp-content/uploads/2021/09/supershot.png" alt="" class="wp-image-8695"/></a></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>The below screenshot is how the response will show up.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8696,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image size-full"><a href="https://qainsights.com/wp-content/uploads/2021/09/supershot-1.png"><img src="https://qainsights.com/wp-content/uploads/2021/09/supershot-1.png" alt="" class="wp-image-8696"/></a></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>To exit the session, type <code>exit</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Let us order a pizza.</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>By leveraging the httpbin.org sample demo app, let us use the HTTP Prompt to send a POST request. HTTP Prompt provides an easy way to interact with the session, just like how you interact with the computer to navigate between folders. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>E.g. <code>cd</code> for change directory, <code>ls</code> or <code>dir</code> to list contents in the current directory etc.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To order a pizza on httpbin.org, below is the POST request that needs to be sent from an HTTP client.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https:&#47;&#47;httpbin.org/post

POST data:
custname=Lilly&amp;custtel=9876543210&amp;custemail=lilly%40example.com&amp;size=medium&amp;topping=cheese&amp;topping=onion&amp;delivery=21%3A00&amp;comments=please+knock+the+door</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>But in HTTP Prompt, you can do this in an interactive way. First, you need to navigate to the URL  https://httpbin.org by issuing the below command. This will create a new session for httpbin.org</p>
<!-- /wp:paragraph -->

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

<!-- wp:paragraph -->
<p>To navigate into /post URL, issue the below command.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>cd post</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>This will navigate into the  http://httpbin.org/post URL.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To order a pizza, you can send the key value pair one by one as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8699,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image size-full"><a href="https://qainsights.com/wp-content/uploads/2021/09/supershot-2.png"><img src="https://qainsights.com/wp-content/uploads/2021/09/supershot-2.png" alt="" class="wp-image-8699"/></a><figcaption>The HTTP Prompt keeps adding the above key value pairs to the request. Once all the payload is added, to send the POST request, just issue the command <code>post</code> inside the session. </figcaption></figure>
<!-- /wp:image -->

<!-- wp:image {"id":8702,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image size-full"><a href="https://qainsights.com/wp-content/uploads/2021/09/supershot-4.png"><img src="https://qainsights.com/wp-content/uploads/2021/09/supershot-4.png" alt="" class="wp-image-8702"/></a></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>To send other methods, you can use the below commands.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>&gt; get
&gt; post
&gt; put
&gt; patch
&gt; delete
&gt; head</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>All the HTTPie commands are valid in HTTP Prompt.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To view all the current session details, issue the <code>env</code> command.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To save the current session, use <code>env &gt; filepath_to_save</code>, e.g. <code>env &gt; ./mysession</code>, this will save the session info to the current location.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To load the current session, use <code>exec ./mysession</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To save the response, use <code>post &gt; myresponse</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To leverage piping, <code>post | grep "data"</code> or <code>post | jq '.data'</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To remove all the options and parameters, <code>rm *</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To add a header, e.g. <code>Content-Type:application/json</code>, auto-fill will assist you find the right syntax.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To send a secret payload, store the content in a file and create a variable that needs to be sent using the below code.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>secret==`cat my_secret_post_payload`</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>The backticks load it from the shell. Send the request using the <code>post</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https://httpbin.org/response-headers&gt; env
cd https://httpbin.org/response-headers
'secret=={"name":"morpheus","job":"leader"}'</code></pre>
<!-- /wp:code -->

<!-- wp:image {"id":8703,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image size-full"><a href="https://qainsights.com/wp-content/uploads/2021/09/supershot-5.png"><img src="https://qainsights.com/wp-content/uploads/2021/09/supershot-5.png" alt="" class="wp-image-8703"/></a></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Configuration Location</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In Windows, the first user config file will be created at, <code>%LOCALAPPDATA%/http-prompt/config.py</code>. Default location is <code>~/.config/http-prompt/config.py</code></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Next Steps</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>HTTP Prompt supports OpenAPI specs using <code>--spec</code>. You can refer to the other important commands from the HTTP Prompt documents. </p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Like HTTP Pie and HTTP Toolkit, HTTP Prompt helps to test and debug HTTP requests in an interactive way with syntax highlighting and color coding. Command-line in nature helps to automate and is easy to incorporate in CI/CD as well.</p>
<!-- /wp:paragraph -->