In most software projects, API testing is done to check the internal quality of the application. Many tools exist to test APIs. This article will discuss Insomnia, a versatile open-source API client that has many features for debugging and testing APIs.
Table of contents
- What is Insomnia?
- Features of Insomnia
- Sample request and response in Insomnia
- How to pass the API key in Insomnia
- Frequently asked questions on Insomnia
- Conclusion
What is Insomnia?
Insomnia is a popular open-source tool for debugging, testing, and documenting APIs (Application Programming Interfaces). It provides a user-friendly interface to send HTTP requests, inspect responses, and organize requests in a structured way. It also supports GraphQL, REST APIs, and WebSocket protocols, making it a versatile tool for developers and testers. Additionally, It’s available for Windows, Mac, and Linux, which can be downloaded from the Insomnia website.
What is Kong Insomnia?
Kong Inc. is a well-known API management enterprise that acquired Insomnia in 2019 and rebranded it as Kong Insomnia. Since then, Insomnia has continuously grown and improved its capabilities by adding new features daily. This has made it even more effective for enterprise-level API management and testing, providing individuals and organizations with every possible API testing need.
Features of Insomnia
Insomnia has a user-friendly interface that helps create and manage HTTP requests for beginners and experienced users. It also supports environment variables, which let users handle different work environments like development, staging, and production. It can be integrated with version control applications like GitHub or GitLab, allowing users to sync their API requests with repositories. Users can also manage their branches and commit changes directly from the application.
Insomnia has a Generate Code option, which helps users generate code in over twelve programming languages. It also supports multiple authentication methods like Basic Auth, OAuth 1.0 and 2.0, API Keys, JWT, and custom authentication schemes. The request chaining feature of Insomnia is another big highlight, which allows users to use responses of one request into another request, which is particularly useful for multi-step workflows, for example, searching for a product in an e-commerce site and then adding it to the cart.
Insomnia also supports GraphQL queries, including features like schema fetching and intelligent autocomplete, making it easier to build and debug queries with real-time error highlighting. Insomnia helps users test connections and send/receive messages for WebSocket testing.
Lastly, we can’t ignore the response-mocking feature of Insomnia, which lets users simulate API responses by helping to test how applications can handle different responses without making actual network requests. All these key features make Insomnia a powerful API development and testing tool.
Sample request and response in Insomnia
To show how to make a request and view the response in Insomnia, we’ll use the URL https://automatenow.io/wp-json/wp/v2/posts, which is an API endpoint used to retrieve information on blog posts for automateNow.
Launch the Insomnia application.
Click on New Collection to create a new request collection.
Click on New HTTP Request button or ctrl + N on Windows.
Name your request, for example, Get automateNow Posts.
Choose the request type, which is GET in this case, and in the URL bar, enter the URL https://automatenow.io/wp-json/wp/v2/posts.
Click the Send button to make the request to the server.
Notice that the request body is empty in a GET request. A POST request, on the other hand, would most likely require that we provide a body.
After sending the request, Insomnia will display the response from the server (e.g., 200 OK) and the response time in the top part of the window.
You can also view the response output of your API under the Preview tab on the right-hand side.
Expanding the Preview dropdown allows the user to access the Raw Data and Source Code of the response.
How to pass the API key in Insomnia
What is an API Key?
An API key is a unique identifier used to authenticate requests made to an API. It works as a secret token that allows the API to verify the application’s identity or the user making the request. API keys help control and monitor API usage, ensuring only authorized users can access certain features or data.
To pass an API key in Insomnia, you can include it in the headers or as a query parameter. Here’s a step-by-step guide using the URL https://linktr.ee/automateNow.
Launch the Insomnia application on your computer. Click on the New HTTP Request button.
Name your request, and in the URL bar, enter the URL https://linktr.ee/automateNow.
Passing API Key in headers
Click on the Headers tab below the URL bar and add a new header by clicking Add.
Add a name type function in the header field and your API key in the value field.
Click the Send button to make the request to the server with the API key included in the headers.
Passing API Key as a query parameter
You can also pass your API Key as a Query Parameter. Here are the steps:
Click on the Parameters tab below the URL bar. Then, Add a new query parameter by clicking Add.
Enter a name in the Name field and your API key in the Value field.
Then, click the Send button to make the request to the server with the API key included in the query parameters.
Frequently asked questions on Insomnia
Is Insomnia better than Postman?
Insomnia and Postman are very popular API testing tools. Which tool is better typically depends on your needs. Insomnia is simple and easy to use, with a clean and user-friendly interface. It is great for both beginners and advanced users. Insomnia makes it easy to create and test API requests quickly. It also has powerful features like advanced scripting, dynamic variables, WebSocket testing, request chaining, and the ability to merge with Git, which lets you handle more complex requests and responses.
Postman, on the other hand, has more features and is ideal for teams working together. It offers tools for automated testing, monitoring, and detailed documentation, which are helpful for large projects. Postman also allows scripting but with some limitations compared to Insomnia. Due to its many features, Postman can be harder to learn. Ultimately, the choice between Insomnia and Postman is whether you prefer a simple tool or one with many features.
Can you run unit tests in Insomnia?
No. Insomnia is primarily designed for API testing rather than unit testing. However, you can automate tests by chaining requests and using environment variables. For comprehensive testing and CI/CD pipelines, you must use tools like Postman or other dedicated testing frameworks like Jest or Mocha.
Is Insomnia a powerful API client?
Yes. Insomnia supports various protocols (REST, GraphQL, WebSockets), which offer strong request and response handling and can be integrated well with different environments. Insomnia plugins allow for adding more features, making them suitable for complex API testing and debugging tasks. Additionally, it supports advanced features like request chaining and environment variables for dynamic testing.
What’s the difference between the free and paid version of Insomnia?
Here’s a comparison of what you get in the free version and what you get with the paid version of Insomnia:
Free Version
- Core API designing, debugging, and collaboration tools.
- You can have unlimited collaborators for a single project.
- Offers end-to-end encryption (E2EE) for secure communication.
- Native support for Git, making version control easier.
Paid Version
- Can invite collaborators and manage them across multiple projects.
- Access to unlimited organizations.
- Role-based access control (RBAC) and permissions management.
- Enterprise single sign-on (SSO) support with protocols like SAML and OIDC.
- Control where your data is stored: cloud, local, or Git.
- Ability to mock APIs locally, supporting self-hosted API mocking.
- Dedicated enterprise-level support.
- Access to Kong Professional Services.
- Custom payment options are available.
- Unlimited mock requests for testing and development purposes.
Final thoughts on using Insomnia for API testing
Of the many API clients available today, Insomnia is a great option for beginner and advanced users. Given that it supports popular APIs such as REST and GraphQL and its advanced features like request chaining and environment variables, it is a great tool to use during API design and testing process. Insomnia simplifies API testing and debugging tasks by integrating with Git for version control and allowing easy handling of API keys.
The free version offers basic tools for individual projects, while the paid version enhances collaboration with advanced features, strong security options, and dedicated support. It’s an excellent choice for teams and larger projects needing complete API testing and management capabilities. Happy testing!
Don’t miss these
Follow our blog
Be the first to know when we publish new content.
- How to find an element in Selenium - October 5, 2024
- Resolved: SessionNotCreatedException - October 2, 2024
- Katalon Recorder Automation Overview - September 12, 2024