Getting Started with Insomnia: How to Use Environment Variables

Watson Kristin - Oct 23 - - Dev Community

Insomnia is a powerful tool for designing, debugging, automated testing, and load testing APIs.

Insomnia api.png

Insomnia supports the concept of environments, which can be used for various purposes such as development, production, sandbox, and mock servers. In this article, we'll detail how to utilize environment variables in Insomnia. Specifically, we'll demonstrate how to set up an "OpenAPI Environment" with values imported from an OpenAPI document.

Step 1: Selecting an Environment

When you open Insomnia, the default environment is "Base Environment." To change this to "OpenAPI env," click on the dropdown menu and select "OpenAPI env." This will make various pre-configured values from the imported OpenAPI document available for use.

Step 2: Setting Up Environment Variables

Sometimes, you may encounter errors when importing an OpenAPI document. For example, when importing the Train Travel API, you might see an error due to improperly configured environment variables.

Setting up Environment Variables in Insomnia

The error displayed in the URL might be:
“attempted to output null or undefined value”

You can fix this error by selecting the _.host variable.

While you need to configure this setting for each operation, it’s not the most ideal scenario. The Insomnia team is aware of this issue, and a fix is expected in the near future.

Setting up Environment Variables in Insomnia

Step 3: Using Environment Variables

Using Environment Variables in Insomnia

Properly setting up environment variables makes API testing in Insomnia highly efficient. You can easily switch between different settings for each environment, facilitating a smooth transition from development to production.

EchoAPI: A Superior Alternative

Lastly, let's introduce EchoAPI as an alternative to Insomnia. EchoAPI is an ultra-lightweight collaboration tool that supports API development. It features API design, debugging, automated testing, and load testing, along with supporting the Scratch Pad feature. EchoAPI also provides plugins for IntelliJ IDEA, VS Code, and a Chrome request capture extension, all without requiring a login. This makes EchoAPI a worthy consideration for developers looking for an alternative to Postman.

An Alternative to Consider: EchoAPI.png

When working on your next API development project, give EchoAPI a try. You won’t be disappointed.

. . . . .
Terabox Video Player