Blog

Testing Tools: Insomnia API Testing

In this post, we will talk a bit about Insomnia, its main features, similarities, and differences with other API testing tools.

What is Insomnia Testing Tool?

Insomnia is a free, cross-platform desktop application that simplifies the interaction and design of HTTP-based APIs. Insomnia combines an easy-to-use interface with advanced features like authentication wizards, code generation, and environment variables.

API Testing Tools: Comparison Chart

The following chart compares the main features of Insomnia with Postman and SoapUI for similarities and differences.

InsomniaPostmanSoapUI
Free, Open Source & PricingFree & PricingFree, Open Source & Pricing
DesktopWeb & DesktopDesktop
-Rest
-SOAP/WSDL -GraphQL
-gRPC
-API Repository
-API Tools
-GraphQL
-Integrations
-SOAP/WSDL
-REST
-GraphQL
-JMS
Workspace: –Personal
-Team
Workspaces:
-Personal
-Team
-Public
Workspaces: -Projects
Collections:
-New Folder, Duplicate, Delete, Settings.
Collections:
-Share, Run, Add Request, Add Folder, Edit, Monitor Collection, Mock Collection, View Documentation, Export, Rename, Duplicate, Delete.
-Authorization, Pre-request script, Test, Variables
-Run
-Share
Projects:
-Test Suites
-TestCases
-Test Steps
Environments:–Variables (JSON)Environments:
-Variables
-Share

Request:
-GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, CUSTOM
-Body
-Auth
-Header
-Query
-Docs
Request:
-GET, POST, PUT, PATCH, DELETE, COPY, HEAD, OPTIONS, LINK, UNLINK, PURGE, LOCK, UNLOCK, PROPFIND, VIEW
-Parameters
-Authorization
-Headers
-Body
-Pre-request
-Script
-Tests
-Settings
Request:
-GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, PATCH, PROPFIND, LOCK, UNLOCK, COPY, PURGE
-Parameters
-Authorization
-Body
-Headers
-Attachments
-Representations
Mock ServersGenerate Mock Service
MonitorsMonitor APIs
Flows

A First Approach to Insomnia

My first tests with the tool were for this review, and the objective of them was to understand what features Insomnia has as well as to know first-hand how it handles both REST and SOAP APIs. Therefore, these tests were carried out against the APIs GoREST and CountryInfoService.

Following the style of the previous post, “Hoppscotch: Open Source API Development Ecosystem”, we want to understand how Insomnia behaves by testing a Rest API versus Postman and a Soap API versus SoapUI.

 I share some screenshots taken during the tests to show what the tool looks like. After downloading and installing it, its use is really intuitive since it presents an interface very similar to Postman.

Proof of Concept: GoREST

GoRest is a Rest API that is available online for testing and prototyping. It allows the registration of users who can publish posts and comments. As this is a testing API it only contains fake data.

To start testing GoREST, create a project in the Insomnia dashboard:

Insomnia deshboard
Insomnia deshboard 2

Being able to manage environments is crucial. That’s why the first thing I did was configure the work environment. To do this, we go to the environments menu and select the Manage Environments or Ctrl+E option:

In the environment manager, we display the options in Sub Environments and select Environment:

With the new environment created, we can click on the name to edit it and start writing the parameters in JSON format:

Once the environment is created, we must select it from the drop-down list:

Within the environment, we create the collections to organize and store the different requests:

Unlike Postman or SoapUI, collections or folders are not exported directly from the context menu, however, in Settings, they can be moved or copied to another Workspace.

To import or export any document or collection from the workspace, go to the menu that is displayed in its name and select Import/Export:

As in similar tools, parameters can be used in requests through environment variables, defined in JSON format.

To invoke any parameter, press Ctrl+Space where you want to insert it, and a list with all the available variables is displayed.

It is also possible to indicate the parameter directly in the Query section of the request:

In the case of sending a POST type request, as in other tools, you can select the type of Body (JSON, XML, YAML, EDN, Plain, Binary File, No Body):

In the case of the API we are testing, it is necessary to send an authorization token that can be added in the Auth section by selecting the type of authorization required:

Insomnia allows you to make requests from cURL. To do this, we copy one of the cURLs offered by the GoRest API as an example and paste it into the request URL:

Likewise, it is possible to send attached files if we select Binary File in the Body:

After selecting the file, the request will look like this:

The result can be seen on the right side of the screen as follows:

Another feature shared with other tools is the response history on the right to be able to trace our work:

Proof of Concept: CountryInfoService

It is a web service that displays country information from a two-letter ISO code, for example, “UY”. It offers functions to recover the currency used, the language, the capital city, the continent, and the telephone code.

To get started, I created another project in the Insomnia dashboard. I also configured the environment and collections of the new Project:

For requests of the SOAP type, what we do is select XML as the Body type and give it the corresponding format (XML):

An important thing: we must select the POST method, although it is possible to use GET in Soap web services, typically, given that this protocol uses verbose payloads, POST is usually used. In addition, it is also necessary to configure the headers:

And we get the answer:

If we prefer to pass data as parameters in the request, we can do it as follows:

Chaining Requests

Insomnia allows the extraction of values ​​from the answers to be used in other requests. For example, using the response ID of a POST method in a GET request. You can see this Documentation for more information.

There are three types of response options:

  • Response – Body Attribute: Works on JSON and XML responses, pulling attributes from a response body.
  • Response – Raw Body: References the entire body contents of a request.
  • Response – Header: Pulls specific header values out of a response.

To specify the data to be obtained from a response, in the empty URL bar, for example, we enter ‘/response’ and the options are displayed.

We select the desired one, in my case I selected Body Attribute. Then we click on the red tag and configure the rest of the options.

In Request we must specify which request we are referring to, we select it from the drop-down list. In Filter, which can be a JSONPath or XPath, we enter the data that we want to obtain from the response, which will be displayed in the Live Preview box.

In the following example in the GoRest project, we use the id obtained from the POST NewUser method response to send a GET UserById request. We pass the data as a request query:

And we configure the tag as follows:

In the following example in the CountryInfoService project, we take the ISO Code from the response of the CountryByName request and pass it to the FullCountryInfoByISOCode request as follows:

As in the previous case, we select the response that contains the data, and in Filter we enter the corresponding XPath:

In this way, we can see that it is different from how data is handled between requests in Postman for example, although Insomnia also allows you to do it through environment variables.

Testing With Insomnia

Unlike Postman or SoapUI, Insomnia offers a separate tab for testing. Previously we were working on the DEBUG tab with the requests and responses. Unit tests are based on the Mocha and Chai framework for assertions, with JavaScript, according to the documentation.

Unit tests can be organized in Suites. They can be run individually or you can run the complete Suite.

Image 1 shows the organization of unit tests in Suites in the left panel.

Image 2 shows the unit tests within the Suite, related to the corresponding request, in the central panel.

And image 3 shows the results of the tests with the time consumed, in the panel located to the right of the workspace.

In the case of the project with SOAP it is the same procedure:

Inso CLI

Inso CLI (Command Line Interface) for Insomnia is based on Node.js and the core Insomnia libraries. It allows you to use Insomnia functionality in terminal and CI/CD environments for automation. At this time, Inso CLI only works with design documents and does not request collections.

There are two ways to install Inso CLI:

  • from an executable that is downloaded from GitHub
  • through NPM insomnia-inso (Node.js 16.x LTS)

Inso Run Test

In my case, I installed it using the first option. After installed, I tried with the commands as explained in the documentation, and this was the result of running the test suites of the GoREST project:

When running the inso run test command without specifying a document, we are prompted to select one from the list. After selecting the document or suite to test, we are asked to select the environment, as shown in the screenshot.

I did the same for the CountryInfoService project:

If a report type (dot, list, spec, min, and progress) is not specified, spec is used by default.

Inso Export Spec

This command extracts and exports the raw OpenAPI specification. The OpenAPI specification is the standard for documenting APIs, and OpenAPI 3.0 is the latest version. OpenAPI 3.0 offers several improvements, such as a simpler structure for defining APIs and more reusable components to reduce duplication.

With the –output <path> option, the specification is saved to a file.

Export the specification loaded in the ‘DESIGN’ tab.

An OpenAPI document describes the public interface of the REST API and defines information such as name and description, the individual endpoints (paths), and how issuers are authenticated. One of the main benefits of using OpenAPI is for documentation; once you have an OpenAPI document that describes your API, it’s easy to generate reference documentation for it.

Inso Generate Config

This command generates a configuration from the API specification declared in DESIGN using openapi-2-kong. The command works similarly to generating a declarative configuration file or Kubernetes manifest from Insomnia. An example can be seen here.

Insomnia allows you to create a preformatted decK file when adding endpoints to the document, or you can take a document and generate a Kubernetes manifest.

Both options are also available in the Insomnia user interface.

Continuous Integration

Inso CLI is designed to run in acontinuous integration (CI) environment, removes the need to interact with the tools through prompts and provides exit codes to pass or fail the CI workflow. An example can be seen here.

Collaboration

To work as a team and to be able to synchronize projects, it is necessary to register in the Insomnia web dashboard. The documentation explains how to work as a team and synchronize projects.

Once entered into the dashboard we can manage the team and add members via email.

Once the work is synchronized, all team members can view the shared dashboard projects on Insomnia desktop.

My dashboard:

A collaborator’s dashboard:

Pros

  • Its paid version is the cheapest compared to Postman or SoapUI (see Pricing table).
  •  It allows you to manage the Cookies of the responses and send them in the requests automatically when necessary.
  • It allows integration with GitHub in a simple way.
  • It allows the handling of variables and data in a simpler way than alternative tools.
  • It allows you to generate code snippets for more than 12 different languages ​​from the requests.
  • It also allows you to import an API swagger in the DESIGN tab from a yaml file or by manually entering the appropriate format.

Cons

  • Environment variables can only be set in JSON format.
  • The test scripts must be entered manually since it does not present snippets like Postman for example.
  • Collaboration and teamwork are only available in the paid version.
  • There’s Little documentation about requests for SOAP.
  • Inso CLI does not work with collections.
  • It’s only available for Desktop in English.
  • Although it presents a dashboard on the web for teamwork management, requests and responses can only be managed from the desktop version.

Final thoughts

Although Insomnia has an interface very similar to Postman, as the work area is divided into 3 ‘tabs’ where different topics are dealt with (DESIGN/DEBUG/TEST), it makes it a more organized tool to work with.

The dashboard that it presents with the different workspace projects and other actions such as creating the documentation, are also user-friendly and help keep our projects organized.

It has very similar features to Postman, but not so to SoapUI. Compared to Postman, I found it to be a very versatile tool when it comes to working with data and variables. In the testing section, it would be better if some snippets were added to help.

Inso CLI allows an approach to test automation allowing to run the suites, although, in my opinion, it would be better to be able to run the collections.

Finally, the integration with GitHub seems to me to be a plus to highlight since nowadays collaborative work on the network is essential.

If you find Insomnia interesting, I invite you to use it and leave me your comments about it.

Looking for a Quality Partner for Performance Testing?

Abstracta is one of the most trusted companies in software quality engineering.

We are quality partners! Learn more about our solutions, and contact us to discuss how we can help you grow your business.

Abstracta Ilustration

Follow us on Linkedin & X to be part of our community!

407 / 436