HTTPie App: How to use Collections and Environments
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.
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.
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.
We can further improve this by naming each Request
and make it vibrant with colours and icons. Below is the improvement
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.
Path | Environment |
http://localhost:8080/employee/1 | Local |
http://my-emp-service-dev/employee/1 | Development |
http://my-emp-service-prod/employee/1 | Production |
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
In summary, Collections and Environments form a strong foundation when using HTTP clients like HTTPie and Postman. Hope you enjoyed this article.
Subscribe to my newsletter
Read articles from Gohit directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by