# nvim-http A Neovim plugin for quick HTTP execution from your notes/code buffers. ## Current status Current features: - `setup()` configuration - Run HTTP commands under cursor - Optional YAML `header(s)` and `body`/`request` blocks under the request line - Telescope response tree with expandable `headers` and nested JSON `result` - `:NvimHttpRun` and `:NvimHttpClear` commands - `:help nvim-http` docs ## Install ```lua { "your-name/nvim-http", dependencies = { "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim", }, build = "rockspec", config = function() require("nvim_http").setup() end, } ``` ## Usage Put cursor on a line like: ```vim curl https://httpbin.org/get ``` Then run: ```vim :NvimHttpRun ``` This opens a Telescope window with: - `response_code` - a collapsed `request` block (`url`, `headers`, `body`) - a collapsed `headers` block - a collapsed `result` block (nested JSON tree when response is JSON) Use `` or `` to expand/collapse the selected node and `q` to close. Default keymap: ```vim hr ``` Default clear keymap: ```vim hc ``` This also supports lines like: - `GET https://httpbin.org/get` - `https://httpbin.org/get` (auto-translated to `curl -sS `) ### YAML blocks under request line You can add request headers/body directly under the request line using YAML blocks: ```text POST https://jsonplaceholder.typicode.com/users headers: Content-Type: application/json Authorization: Bearer token body: name: Jane username: jane1 ``` Also accepted block names: - `header` or `headers` - `body` or `request` Parsing rules: - only lines directly under the request are scanned (bounded lookahead; not whole file) - leading whitespace is ignored - only the first `header(s)` and first `body`/`request` block are used - parsing stops once both blocks are found - parsing also stops if another top-level block appears after parsing started - request blocks are currently applied to curl-style requests - YAML block decoding requires the `lyaml` Lua rock Examples: ```text url header: X-Test: 1 body: a: 1 ``` uses both `header` and `body`. ```text url header: X-Test: 1 body: a: 1 header2: ignored: true ``` stops after `body`, so `header2` is ignored. ```text url header: X-Test: 1 header2: nope: 1 body: ignored: true ``` stops when `header2` is reached, so `body` is ignored. ```text url body: a: 1 header: X-Test: 1 ``` works (body-first order is accepted). ## Configuration ```lua require("nvim_http").setup({ http = { enabled = true, execute_keymap = "hr", clear_keymap = "hc", timeout_ms = 10000, highlight_group = "Comment", command_patterns = { "^curl%s+", "^http%s+", "^wget%s+", "^%u+%s+https?://", "^https?://", }, }, }) ``` ## Layout - `plugin/nvim-http.lua`: User command registration - `lua/nvim_http/init.lua`: Plugin API and HTTP runner - `lua/nvim_http/config.lua`: Defaults and config merging - `doc/nvim-http.txt`: Help documentation