Nuxtstop

For all things nuxt.js

HTTP Prompt for Performance Engineers

HTTP Prompt for Performance Engineers
19 0

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 HTTPie and HTTP Toolkit utilities for performance testers and engineers. Let us get started by installing it.

How to install HTTP Prompt?

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.

pip install http-prompt

P.S: using the sudo on pip is not recommended.

If you would like to upgrade, issue the below command.

pip install -U http-prompt

To validate the installation, issue the below command.

http-prompt --version

HTTP Prompt Features

HTTP Prompt has all the essential features for testing HTTP requests. But what is unique in HTTP Prompt is the following features: interactive, auto-complete and syntax highlighting.

Other features are:

  • Auto Cookies
  • OpenAPI/Swagger Integration
  • Unix-like Pipelines
  • HTTPie compatible

Hello World

To start HTTP Prompt, open the command line prompt and issue the below command to start a session targetting https://example.com

http-prompt https://example.com

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.

The below screenshot is how the response will show up.

To exit the session, type exit.

Let us order a pizza.

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.

E.g. cd for change directory, ls or dir to list contents in the current directory etc.

To order a pizza on httpbin.org, below is the POST request that needs to be sent from an HTTP client.

https://httpbin.org/post

POST data:
custname=Lilly&custtel=9876543210&custemail=lilly%40example.com&size=medium&topping=cheese&topping=onion&delivery=21%3A00&comments=please+knock+the+door

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

http-prompt http://httpbin.org

To navigate into /post URL, issue the below command.

cd post

This will navigate into the http://httpbin.org/post URL.

To order a pizza, you can send the key value pair one by one as shown below.

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 post inside the session.

To send other methods, you can use the below commands.

> get
> post
> put
> patch
> delete
> head

All the HTTPie commands are valid in HTTP Prompt.

To view all the current session details, issue the env command.

To save the current session, use env > filepath_to_save, e.g. env > ./mysession, this will save the session info to the current location.

To load the current session, use exec ./mysession.

To save the response, use post > myresponse

To leverage piping, post | grep "data" or post | jq '.data'.

To remove all the options and parameters, rm *

To add a header, e.g. Content-Type:application/json, auto-fill will assist you find the right syntax.

To send a secret payload, store the content in a file and create a variable that needs to be sent using the below code.

secret==`cat my_secret_post_payload`

The backticks load it from the shell. Send the request using the post.

https://httpbin.org/response-headers> env
cd https://httpbin.org/response-headers
'secret=={"name":"morpheus","job":"leader"}'

Configuration Location

In Windows, the first user config file will be created at, %LOCALAPPDATA%/http-prompt/config.py. Default location is ~/.config/http-prompt/config.py

Next Steps

HTTP Prompt supports OpenAPI specs using --spec. You can refer to the other important commands from the HTTP Prompt documents.

Conclusion

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.