HTTPie App: How to use Collections and Environments

GohitGohit
2 min read

Table of contents


HTTPie is an Open Source command line HTTP client. We can also use the App at https://httpie.io/app. In this article, we'll explore effective ways to use the features of the App. We also have an option to download HTTPie desktop to work locally.

💡
Use the Desktop version when working on project activities.

This article's focus is on organizing your Requests and managing secrets. The two features we discuss are

  • Collections

  • Environments

Collections

Organizing our requests is the first thing we need to do when working on large projects. Below is an example of multiple Requests unorganized.

Requests unorganized

Things will quickly get messy when we have many Requests and that is where we have to use Collections.

Simply put, we create a Collection for Requests of the same service and below is an example to represent it.

Requests organized Part 1

We can further improve this by naming each Request and make it vibrant with colours and icons. Below is the improvement

Requests organized Part 2

Environments

Every request has two common properties

  • Different environments that cater to DEV, TEST, PROD etc.

  • Authentication mechanism

Let's dive into a single request from our previous example:

Search EmployeeId with the request

http://my-emp-service/employee/1

The path can take different names in different environments.

PathEnvironment
http://localhost:8080/employee/1Local
http://my-emp-service-dev/employee/1Development
http://my-emp-service-prod/employee/1Production

We don't want to create the same request multiple times for different environments. So let's modify the request

{{url}}/employee/1

Now {{url}} is a variable which can be replaced by the correct values using Environments.

The use of variables is especially important when you have Authentication mechanisms for your Requests

Let's take an example of the previous request and add a Basic Authentication.

This can be replaced with variables {{username}} and {{password}} and have these variables added in the Environment configuration as below

💡
Creating Environments helps you while screen sharing with colleagues without showing up secrets.

In summary, Collections and Environments form a strong foundation when using HTTP clients like HTTPie and Postman. Hope you enjoyed this article.

3
Subscribe to my newsletter

Read articles from Gohit directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Gohit
Gohit