How to install and use the HTTP prompt in Linux

In this article, we are going to discuss the installation process and use cases of HTTP Prompt. HTTP Prompt is an interactive command-line HTTP client which is used for testing and debugging purposes and built on HTTPie and HTTP Toolkit. It has a special feature of auto-complete, interactive, and syntax highlighting. It has other features as well such as auto cookies, Unix-like pipelines, OpenApi/Swagger Integration, and HTTpie compatibility.

Installing the HTTP Prompt in Linux

To install HTTP Prompt, python and pip must need to be installed already. You can then install HTTP prompt as given below by using the pip command.

$ pip install http-prompt

Install HTTP-prompt

Note: While using pip command, using sudo is not recommended.

Upgrading the HTTP Prompt:

$ pip install -U http-prompt

Validating the installation of HTTP Prompt:

$ http-prompt --version

Using the HTTP Prompt in Linux

For the session to start, run the command as shown below:

$ http-prompt

Start http-prompt

As the session starts, you can try using such commands as below:

$ http-prompt

Get URL

Here, we are using httpie get to check how Http Prompt is requesting get for Httpie.

You can also send other methods for which you can use below commands:

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

For example:

Lets run another session for https://example.com by typing this command on the command line terminal. The session will be started for a given url by starting http-prompt as shown below.

$ http-prompt https://example.com

This command will create a session where we can interact by issuing the command which displays HTTP response. As HTTP Prompt has an auto-complete feature, it will show us the option to auto-complete the command which makes it simpler to use.

Start http-prompt session

You can see the auto-complete options just by putting a post on the above picture.

Now, after putting a post on the current session, you will see the output as follows.

POST request

Second example

Let's run a session for https://sample.com by typing this command on the command line terminal. Session will be started for a given url by starting http-prompt as shown below.

$ http-prompt http://www.sample.com

This command will create a session where we can interact by issuing the command which displays HTTP response. As HTTP Prompt has an auto-complete feature, it will show us the option to auto-complete the command which makes it simpler to use.

Now, after putting a head and get on the current session, you will see the output as follows.

Using head and get commands

Here, we run head and get methods which results as shown in the above picture for the particular site.

By using the syntax as in HTTPie, we can add headers, querystring or body parameters. You can see below for further details.

# For Header

> Content-Type:application/json

# QueryString parameter

> page==4

# Body Parameters

> username=linux

> full_name='linux ways'

# Body Parameters in raw JSON

> number:=8569

> is_ok:=true

> names:=["linux","ways"]

> user:='{"username": "linux", "password": "lways"}'

# Write all in one line

> Content-Type:application/json page==4 username=linux

We can also add HTTPie options as shown below:

> --form --auth user:pass

> --verify=no

# HTTPie options and request parameters in single line

> --form --auth user:pass username=linux Content-Type:application/json

Now, you can remove all options and parameters with below command:

> rm *

Also, you can simply exit the session with below command:

> exit

Conclusion

HTTP Prompt is used for testing and debugging HTTP requests in an interactive way with a feature of auto-complete the commands and syntax highlighting as well. It is a good ally of HTTPie. Thank you!

Leave a Comment