Skip to content
lex edited this page Jul 26, 2026 · 2 revisions

Import & Cross-File Execution

Importing Specs

Convert OpenAPI, Swagger, or Postman specs into .http files.

OpenAPI 3.x

:PosteImportOpenAPI
  1. Select an OpenAPI 3.x spec file (JSON or YAML)
  2. Select an output directory
  3. .http files are generated with all endpoints, parameters, and schemas

Swagger 2.0

:PosteImportSwagger

Same flow as OpenAPI import. Converts Swagger 2.0 to .http format.

Postman Collection

:PosteImportPostman

Converts Postman Collection v2.1 JSON to .http files.

Generated Output

Imported specs generate .http files with:

  • @base_url definition at the top
  • @var definitions for query, path, cookie, and form body parameters
  • Named request blocks for each endpoint
  • Default values from the schema where available

Cross-File References (import / run)

Reference and execute requests across files.

Import

Make request names from another file available:

import ./shared-vars.http

With alias (namespace isolation):

import ./auth.http as auth

Run

Execute a request from another file:

run #Login

Run with alias:

run #auth.GetToken

Run with variable overrides:

run #Login (@env=staging, @timeout=30)

Run all requests in a file:

run ./setup.http

Run all with overrides:

run ./setup.http (@env=production)

Variable Overrides

Overrides in run take the highest priority in the resolution chain:

run #CreateUser (@role=admin, @department=engineering)

These override block-level, file-level, and env variables.

Nested Imports

Imported files can themselves import other files. The resolution is recursive.

Script Support

Target blocks with pre/post scripts are executed normally when run via run directive. client.global variables persist across the entire chain.


Lua Import (import ./vars.lua as alias)

Import Lua variables into .http files. No external runtime needed — runs on Neovim's built-in LuaJIT.

Defining Variables

Create a Lua file that returns a table:

-- variables.lua
local M = {}

M.an_int = 100
M.a_string = "hello"
M.a_float = 3.14
M.a_bool = true

M.person = { name = "Lex", age = 23, role = "admin" }
M.tags = { "rust", "lua", "neovim" }
M.config = { endpoint = "https://api.example.com", timeout = 5000 }

M.users = {
  { id = 1, name = "alice", email = "alice@test.com" },
  { id = 2, name = "bob",   email = "bob@test.com" },
}

return M

Usage in .http files

import ./variables.lua as m

@my_person = m.person
@first_tag = m.tags[1]

### Inline substitution
GET {{base_url}}/anything/{{m.an_int}}
X-Name: {{m.a_string}}

### Nested path
GET {{base_url}}/user/{{m.person.name}}
X-Age: {{m.person.age}}

### Array index
GET {{base_url}}/tag/{{m.tags[1]}}

### @var assignment (body expands via {{}})
@my_data = m.person

POST {{base_url}}/anything
Content-Type: application/json

{{my_data}}

### Direct alias in JSON body
POST {{base_url}}/anything
Content-Type: application/json

{
  "name": "{{m.person.name}}",
  "age": {{m.person.age}},
  "tags": ["{{m.tags[1]}}", "{{m.tags[2]}}"],
  "config": {{m.config}}
}

Supported patterns

Pattern Example Result
{{m.key}} {{m.an_int}} 100
{{m.nested.key}} {{m.person.name}} "Lex"
{{m.array[N]}} {{m.tags[1]}} "rust"
{{m.deep.nested[N].key}} {{m.users[1].name}} "alice"
@var = m.keypath @x = m.person @x = {"name":"Lex","age":23}
{{var}} (via @var) {{my_data}} {"name":"Lex","age":23}

Notes

  • Array indexing uses Lua convention (1-based): tags[1] is the first element
  • Lua module is loaded once per file path and cached
  • No Node.js or external runtime required

Clone this wiki locally