DEV Community

Cover image for Basic usage of Insomnia
EmmaHan20220928
EmmaHan20220928

Posted on

Basic usage of Insomnia

Insomnia

It's an API design platform like postman. Most function, except Sync, is free.

1.Download

Insomnia

2.Basic Usage

(If you already know all the buttons, just skip.)

2.1 Create new collection

Insomnia app

2.2 Create new folder and http request

In new collesction

2.3 Folder settings

Right click the folder, choose settings.

In settings, you could change the folder name(F2 cannot) and click add description about the folder.

All the description will show in the final export document.

Right click the folder

Setting image

2.4 Request Area

JSON: request body. could choose any other type.
Bearer: choose token type, add value.
Query: add fields. could use [gt] to filter data
Header: request header.
Doc: single request document

Request area

2.5 Add Environment

Click add button beside Sub Environments.

Add environment variable in the right area.

Caution: every field and value must be wrapped in "", including the Insomnia variable(will be mentioned later).

button

Environment management

3 Common scenario

Doesn't like postman, Insomnia can only use build in method or plugins.

3.1 Reuse a token from login request

Scenario description:

1) Login response body will contain a token;
2) You need the token to make other requests;

Login image

Steps to follow:

1) Open the environment, create a token variable.

In value, type a 'r'(or any other character, wait a second, Insomnia will show a list to choose from) and choose 'Response => Body Attribute'.

2) Click the 'Response => Body Attribute', config the method in 'Edit Tag'.

3) It used JSONPath to filter token.

4) Refer the variable in the headers. Type 't' and it will show the variable list.

Environment variable

Method config

Request Image

3.2Reuse token from cookie

Scenario description:

1) Using cookie to send and receive token.

As shown in the login request image.

2) request send token prefix with bear.

Login request

Steps to follow:

1) Choose 'Bearer', type in cookie and click it to config.

2) Choose your url and type in cookie name and then you can copy it to any request you want.

Cookie

Cookie manage

4 Create Document

I only find the way using command line, don't know if there is other.

Reference doc

To follow the steps, you need to download insomnia-documenter first.

  1. Click the collection and choose 'import/export'.
  2. Choose current project in 'Export data'.
  3. Choose 'Insomnia v4(JSON)' format in export.
  4. In the export folder, use 'cmd' to open the terminal and type as below. (Remember to replace 'filename' to your export filename) npx insomnia-documenter --config filename.json --output insomnia-final-result
  5. 'insomnia-final-result' is your final document. Use VScode or command line to open.

Export

Current report

Choose export request

Choose format

Document in browser

If you have better solution, please do leave comment below.

Thank you!

Top comments (0)