Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Insomnia templates during import #164

Open
LucasPickering opened this issue Apr 19, 2024 · 0 comments
Open

Parse Insomnia templates during import #164

LucasPickering opened this issue Apr 19, 2024 · 0 comments
Labels
help wanted Extra attention is needed qol Improvements that make usage smoother, without introducing new functionality

Comments

@LucasPickering
Copy link
Owner

LucasPickering commented Apr 19, 2024

Insomnia has template-like strings that provide similar functionality to chains. It'd be nice to parse these and convert them to chains during import. This would be pretty complex though. Here's an example of a request with a template:

{
  "_id": "req_30f68ae3069b4ec59707bf793a4b74cb",
  "parentId": "fld_2b83df7de20d446f91d94dcb0b66c06f",
  "modified": 1712668874211,
  "created": 1710623967061,
  "url": "https://httpbin.org/get",
  "name": "Bearer Auth",
  "description": "",
  "method": "GET",
  "body": {},
  "parameters": [],
  "headers": [
    {
      "name": "User-Agent",
      "value": "insomnia/8.6.1"
    }
  ],
  "authentication": {
    "type": "bearer",
    "token": " {% response 'body', 'req_3bc2de939f1a4d1ebc00835cbefd6b5d', 'b64::JC5oZWFkZXJzLkhvc3Q=::46b', 'when-expired', 60 %}"
  },
  "metaSortKey": -1712668874167,
  "isPrivate": false,
  "pathParameters": [],
  "settingStoreCookies": true,
  "settingSendCookies": true,
  "settingDisableRenderRequestBody": false,
  "settingEncodeUrl": true,
  "settingRebuildPath": true,
  "settingFollowRedirects": "global",
  "_type": "request"
},

This could be converted to something like:

chains:
# This ID would have to be auto-generated somehow
  req_30f68ae3069b4ec59707bf793a4b74cb_authentication_token:
    source: !request
      recipe: req_3bc2de939f1a4d1ebc00835cbefd6b5d
      trigger: !expire 60s
    sensitive: true
    selector: $.headers.Host # This is decoded from the base64 content

requests:
  req_3bc2de939f1a4d1ebc00835cbefd6b5d: !request
    name: Login
    method: POST
    url: https://httpbin.org/anything/login
    body: null
    authentication: null
    query: {}
    headers: {}

  req_30f68ae3069b4ec59707bf793a4b74cb: !request
    name: Bearer Auth
    method: GET
    url: https://httpbin.org/get
    body: null
    authentication: !bearer "{{chains.req_30f68ae3069b4ec59707bf793a4b74cb_authentication_token}}"
    query: {}
    headers: {}

The Slumber collection we come up with is still pretty ugly, so not sure if this is worth the effort. I'm sure there's a ton of different settings in Insomnia we'd have to support too.

@LucasPickering LucasPickering added the qol Improvements that make usage smoother, without introducing new functionality label Apr 19, 2024
@LucasPickering LucasPickering added the help wanted Extra attention is needed label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed qol Improvements that make usage smoother, without introducing new functionality
Projects
None yet
Development

No branches or pull requests

1 participant