Insomnia: [Feature Request] Command line API (import/export, send request)

Created on 12 Sep 2017  路  22Comments  路  Source: Kong/insomnia

  • Insomnia Version: 5.8.2
  • Operating System: Mac OS X

Detaills

A command line API for import/export of workspaces or sending a request with a specific environment would be great.
Or is this even possible?
Thanks in advance!

accepted needs discussion

Most helpful comment

Currently use newman (postman cli) for executing api tests on CI. Store test suites in postman format.
It`s not comfortable - to update something in tests, I need to pull changes from VCS, import to postman, edit, export and then push.
It would be great if insomnia has similar feature but with direct load-save-to-file option, like other IDE-s.

All 22 comments

+1 for this. We are evaluating Insomnia in the context of using it as a headless test runner. The benefit would be that all developers can write their API specifications, regardless of desktop environment. Being able to use that resulting insomnia files with a CLI version on a docker container would be gold in this scenario 馃槃

Anything planned? How hard would it be to factor out the UI and create a standalone core that could be run as a CLI client (I'm not above offering my time for that)?

A headless CLI for running tests would be great. To be useful to us, it would have to be capable of running inside of Travis.

This is something I've thought about for a while, but could never figure out a good way to interact with it. How would you prefer to reference the request? The only way I can see at the moment is by finding and using the unique ID that each one has. However, that seems like it would be extremely painful.

I'll let you know once I play around with postman for awhile and figure out its pain points! :)

Oh ya, I forgot Postman had a CLI. Seems like a good place to start!

Report back with what you find 馃槃 馃憤

Hey @mgraham, did you get a chance to play around with the Postman CLI?

Not yet - still mostly figuring out how to set up test cases in the app itself. Our goal is to have them running in travis, which will require getting them working in the CLI.

I want to add my support to adding a CLI for Insomnia to use it as a headless test runner. This is one of the reasons we pay for a Postman Pro account, but I would love to dump Postman Pro in favor of Insomnia.

Yeah, Postman is so clunky!

One opportunity for Insomnia to improve upon Postman would be allowing referring to a specific test case (and all of its template data, etc.) by a URL.

With Postman, we create a test case, and then in Pivotal Tracker聽stories and our Github PRs, we refer to the Postman test case and template by their _names_. It makes for a very manual QA process.

Another great feature (and I realize this is a long shot) would be to integrate with some sort of click testing tool like Selenium; so you could do things like:

  • run an API POST test to set up some data
  • click in the UI of the app to see if the data is there. Make changes
  • run an API GET test to make sure the data is still there

I realize that click testing is completely out of scope for an API tool, but maybe there's some sort of fancy integration with a click testing tool that would make interleaved API tests and click tests possible.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

why is this closed? I Googled here because this feature is what I am looking for. if it were around I'd be using it right now.

Yeah, I'd say it's still an important issue.

I think that you should start with a simple cli that just exports and imports Insomnia settings.
IMHO, it's "easy" to do and does not require discussion.

fyi, it looks like that someone is taking action. https://www.npmjs.com/package/insomnia-cli

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I think it's still a valid long-term feature request

I wanted something which postman can't give and won't give.

  • First I'd like a save location for individual collection, this way I have the ability to save my requests right on my git source control (not sure if it's already there)
  • then I'd like to just run a cli clinsomnia run ./collection which would then run everything and execute tests

I would love to see a stable, headless command line runner for insomnia request collection exports.

insomnia-cli (or as I like to call it, insomniac, because hey, here we're trying to run requests like a robot, not a human) was a rough experiment to see what a command line HTTP request runner of insomnia exports would look like.

Two design features give insomnia a huge advantage over postman:

  • Immutable environment variables (scoped to an insomnia export). Result: more stable and deterministic
  • Previous-response data dependencies must be declared explicitly through a tag (the response value tag). Result: existing semantics can be leveraged for faster, concurrent execution

These two features combined allows insomnia-cli to automatically figure out how to run requests concurrently! The request call graph can be determined through the response value tags (it's a directed acyclic graph unless there's a closed cycle of response tags). And immutable environment variables eliminate error-prone manual variable management (looking at you, postman test scripts). During the runtime, the runner only needs to be responsible for making requests, exposing the result to subsequent requests, and then rendering the overall results to console output. Any request that fails (hopefully based on a user-defined condition) can fail an entire sub-tree of the graph.

insomnia-cli was hacked together over a weekend, so the smallest steps were taken to get the above concept working. ~The git history and thus diff was lost when just the insomnia-app sub-package was ported over.~ But the basic approach was to re-use the existing packages published to the @insomnia scope and rip out all the pieces that might invoke the electron UI rendering.

The set of requests to run are specified by top-level folder names鈥攁ll the requests in the folder will be run. If there are no response value tag dependencies, all the requests will just be run together. The object of environment variables is specified by sub-environment name. This is due to my own usage pattern: I鈥檝e never added to or used the global environment.

Separating out the core from the UI would help with this in the future. The core piece would only expose an API for the networking, persistence, and Insomnia-specific resources. Then the electron UI and a command line runner could be two frontends to the same insomnia core.

Edit: Actually, found the initial fork and UI removal commits: https://github.com/mtso/insomnia/commits/cli

Currently use newman (postman cli) for executing api tests on CI. Store test suites in postman format.
It`s not comfortable - to update something in tests, I need to pull changes from VCS, import to postman, edit, export and then push.
It would be great if insomnia has similar feature but with direct load-save-to-file option, like other IDE-s.

@alexus1024 dredd is fantastic for running tests against the examples in a swagger/OAS contract (v2 x-example; v3 examples). It's _not_ a cli for a general purpose req/res tool (and is therefore not as customisable as newman), but for no-fuss testing with an existing contract, I consider it peerless.

Here is a Node.js script to export a workspace from Insomnia. It mostly boils down to this function https://github.com/dgroomes/nedb-playground/blob/0d20d10407408dfa6cd6a8d16ccd27ef65249a74/insomnia.js#L84

You use it with npm install && node insomnia.js and then it writes a valid Insomnia export file. (It hardcodes some things too). It was a good refresher for me for JavaScript (never used async/await) and to learn NeDB.

+1 for the CLI-based export/import feature request. If I had it then I think it would motivate me to export my 100+ requests that I've created over the years (the APIs for lots of DevOps tools and the APIs of our own system) and share them in version control for my colleagues! If I can get into a workflow of easily syncing my workspace with Git, that would be ideal. I see some really cool "Git syncing" and CLI functionality (inso) in the new Insomnia Designer! I would like to have that same functionality in Insomnia Core for exporting/importing (and maybe even diffing?) requests/workspaces.

I'm happy to try to restructure some things in Insomnia but didn't know where to start. Do you view that inso could evolve to interact with Insomnia Core and not just Designer?

Was this page helpful?
0 / 5 - 0 ratings