Access Your REST APIs with HTTPie

Javatechie
3 min readMar 12, 2020

--

Modern Command Line HTTP Client

Basic Introduction about HTTPie

HTTPie (pronounced 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.

It provides a simple http command 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.

Installation (Windows OS)

  1. Download the Windows x86–64 executable installer and run it.

2. Once you install this python version then next step we need to Install pip/Python and upgrade pip

python -m pip install — upgrade pip

3. Install pip setup-tools , run below command

pip install — upgrade pip setuptools

4. Install HTTPie , run below commands

pip install — upgrade httpie

Cool , Now we are done with installation stuff , so let’s begin with Usages

Example with HTTP Methods

Already i created one spring boot CRUD Example let’s access all the REST Endpoints with HTTPie Command Line client

POST Method :

HTTP URL : http POST http://localhost:9191/addProduct name=bike quantity=1 price:=90000

If you observe /addProduct is Endpoint URL and name,quantity & price are Request Body to access REST API

GET Method :

HTTP URL : http GET http://localhost:9191/products

This Endpoint will return list of product object available in DataBase

GET Method with Argument :

HTTP URL : http GET http://localhost:9191/product/mobile

This Endpoint will return Product object by name where name is request path argument

HTTP PUT Method:

HTTP URL : http PUT http://localhost:9191/update id=6 name=bike quantity=1 price:=190000

Usually PUT method used for UPDATE operation , so if you noticed we were giving request body to update (Verify with POST method price for Bike previously it was 90000 now we are updating price to 190000)

HTTP DELETE Method :

HTTP URL : http PUT http://localhost:9191/delete/6

Wrapping Up

HTTPie is a light-weight but extremely powerful tool to communicate easily with an HTTP server. The ability to invoke a variety of HTTP methods with an HTTP command and other sensible default values makes it a perfect candidate in RESTful and microservices ecosystem …

--

--

Javatechie
Javatechie

Written by Javatechie

A software developer on JDK and JEE platform. I am passionate about Java technology and always an explorer and learner in new technologies

No responses yet