Debug APIs like a human with Insomnia


As a developer, you’ll work with an Application Programming Interface (API) in one way or another. APIs appear in many places, from operating systems to the use of external services such as weather forecasts in applications. APIs allow developers to build faster and concentrate on delivering the best experience to users. Imagine a world without APIs. It’s hard to imagine — probably impossible. APIs have quickly become a common way of delivering services. Insomnia, a small but powerful tool, can come in handy when working with APIs. In this post, I will go over the basics of Insomnia.

In a previous post, I covered another tool for working with APIs that is also worth checking out. Both tools are very helpful when using and building APIs. When we speak of APIs, usually what we’re talking about are RESTful APIs. A Representational State Transfer-ful API takes advantage of existing protocols like HTTP.  

Working with APIs has become an essential skill. But sometimes, working with APIs can be daunting. Enter Insomnia!

Getting started with Insomnia

Insomnia is open source and completely free software, but a Plus or Teams account subscription provides some additional features. (The free version will suffice in most cases.) It’s supported on Windows, Mac, and Linux. Download the relevant version from the application homepage. After installing and launching the app, you should see an interface similar to the one in the image.

GET something to the POST

We’ll follow tradition here by making GET and POST requests to a fake API: Req | Res. Reqres allows developers to quickly test the front-end against an API with fake data without having to build an API themselves.

To send our first GET request, we create a new request with the Ctrl+N keyboard shortcut (or the equivalent, depending on your setup). The same process can be achieved by clicking on the tiny plus icon on the left side pane and selecting new request.  

In the pop-up window, give the new request a name, and select the appropriate request type — GET, in this case. Then click on Create. This activates the center pane so you can see the input box for the API endpoint, and the following tabs: Body, Auth, Query, Header, and Docs. These options give users even finer-grained control over requests.

Enter this URL and click send: The API responds with JSON data of some users. The data can be seen in the response pane at the right.

The process for a POST request is quite similar, except that the request method becomes POST. Other methods such as PUT, PATCH, DELETE, and HEAD are supported.

Do you speak Java?

A really impressive Insomnia feature is the ability to generate code snippets for many languages. This ensures developers don’t waste time debugging API requests in programming languages. Just make the request with Insomnia, and if it works, you generate the code for the programming language of your choice: Go, Python, Java, C, NodeJS, etc. Simple!

To do this, select the little drop-down by the request name, and select Generate Code. From the pop-up, select the language and options, and you’ll see the corresponding code. You can copy and paste this into your project, and it will work just fine.

Even more

There are more handy features that make Insomnia fun to use. The variety of themes gives users several options to pick from based on their preferences. (Yes, there are dark themes.) HTML responses can be previewed as web pages instead of code.

Insomnia provides support for GraphQL, a query language for APIs, as well as the runtime for fulfilling queries with existing data. GraphQL is modern and makes it easier to deal with APIs, and gradually seeks to replace REST.

Other features include SSL client certificates, reusable variables, NTLM authentication, etc.

Closing thoughts

We’ve seen a simple yet powerful tool for working with APIs. Insomnia comes in very handy, and as a developer, it’s a tool worth having in your toolbox. Make sure to consider Insomnia whenever you work with an API so you can have some REST.

Bruno is a junior at Ashesi University College studying Computer Science. He is interested in leveraging the power of technology to increase productivity. As a big fan of open source technology, he is currently exploring the possibility of using the Bitcoin Blockchain to fight corruption in government. Bruno is a regular contributor at Fixate IO.


Click on a tab to select how you'd like to leave your comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Skip to toolbar