mirror of
https://github.com/macocianradu/nvim-http.git
synced 2026-03-18 21:00:05 +00:00
3.0 KiB
3.0 KiB
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)andbody/requestblocks under the request line - Telescope response tree with expandable
headersand nested JSONresult :NvimHttpRunand:NvimHttpClearcommands:help nvim-httpdocs
Install
{
"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:
curl https://httpbin.org/get
Then run:
:NvimHttpRun
This opens a Telescope window with:
response_code- a collapsed
requestblock (url,headers,body) - a collapsed
headersblock - a collapsed
resultblock (nested JSON tree when response is JSON)
Use <CR> or <Tab> to expand/collapse the selected node and q to close.
Default keymap:
<leader>hr
Default clear keymap:
<leader>hc
This also supports lines like:
GET https://httpbin.org/gethttps://httpbin.org/get(auto-translated tocurl -sS <url>)
YAML blocks under request line
You can add request headers/body directly under the request line using YAML blocks:
POST https://jsonplaceholder.typicode.com/users
headers:
Content-Type: application/json
Authorization: Bearer token
body:
name: Jane
username: jane1
Also accepted block names:
headerorheadersbodyorrequest
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 firstbody/requestblock 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
lyamlLua rock
Examples:
url
header:
X-Test: 1
body:
a: 1
uses both header and body.
url
header:
X-Test: 1
body:
a: 1
header2:
ignored: true
stops after body, so header2 is ignored.
url
header:
X-Test: 1
header2:
nope: 1
body:
ignored: true
stops when header2 is reached, so body is ignored.
url
body:
a: 1
header:
X-Test: 1
works (body-first order is accepted).
Configuration
require("nvim_http").setup({
http = {
enabled = true,
execute_keymap = "<leader>hr",
clear_keymap = "<leader>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 registrationlua/nvim_http/init.lua: Plugin API and HTTP runnerlua/nvim_http/config.lua: Defaults and config mergingdoc/nvim-http.txt: Help documentation