1414
1515</div >
1616
17- # ⚠️ NOTICE
18-
19- Currently my focus is university and other projects, which is why I have no interest in rest.nvim and it's extremely difficult for me to work on bugs or features of a plugin that I have not used for a long time and that in the time that I've used it, it works perfectly on my computer. That said, I have looked for another maintainer for the project but I have never been able to find it, so I have decided that it's best to archive it and hope that in the future someone makes better software than me and is willing to maintain it.
20-
2117---
2218
2319A very fast, powerful, extensible and asynchronous Neovim HTTP client written in Lua.
@@ -52,19 +48,11 @@ CLI. For more information on this, please see this [blog post](https://amartin.c
5248### Dependencies
5349
5450- System-wide
55- - ` Python ` (only if you are using ` packer.nvim ` or ` lazy.nvim ` plus ` luarocks.nvim ` for the installation)
56- - ` cURL ` development headers (usually called ` libcurl-dev ` or ` libcurl-devel ` depending on your Linux distribution)
51+ - ` curl `
5752- Optional [ can be changed, see config below] ( #default-configuration )
5853 - ` jq ` (to format JSON output)
5954 - ` tidy ` (to format HTML output)
6055
61- > [ !NOTE]
62- >
63- > 1 . Python will be unnecessary once ` luarocks.nvim ` gets rid of it as a dependency in the ` go-away-python ` branch.
64- >
65- > 2 . I will be working on making a binary rock of ` Lua-cURL ` so that the ` cURL ` development headers are not
66- > necessary for the installation process.
67-
6856### [ rocks.nvim] ( https://github.com/nvim-neorocks/rocks.nvim ) (recommended)
6957
7058``` vim
@@ -74,39 +62,17 @@ CLI. For more information on this, please see this [blog post](https://amartin.c
7462### [ lazy.nvim] ( https://github.com/folke/lazy.nvim )
7563
7664``` lua
77- {
78- " vhyrro/luarocks.nvim" ,
79- priority = 1000 ,
80- config = true ,
81- opts = {
82- rocks = { " lua-curl" , " nvim-nio" , " mimetypes" , " xml2lua" }
83- }
84- },
8565{
8666 " rest-nvim/rest.nvim" ,
87- ft = " http" ,
88- dependencies = { " luarocks.nvim" },
89- config = function ()
90- require (" rest-nvim" ).setup ()
91- end ,
9267}
9368```
9469
95- > [ !NOTE]
96- >
97- > There's a ` build.lua ` file in the repository that ` lazy.nvim ` will find and source to install the
98- > luarocks dependencies for you by using ` luarocks.nvim ` . You don't need to specify a rock list
99- > by yourself.
100-
10170### [ packer.nvim] ( https://github.com/wbthomason/packer.nvim )
10271
10372``` lua
10473use {
10574 " rest-nvim/rest.nvim" ,
106- rocks = { " lua-curl" , " nvim-nio" , " mimetypes" , " xml2lua" },
107- config = function ()
108- require (" rest-nvim" ).setup ()
109- end ,
75+ rocks = { " nvim-nio" , " mimetypes" , " xml2lua" , " fidget.nvim" },
11076}
11177```
11278
@@ -120,66 +86,98 @@ get a good experience during autocompletion :)
12086> You can also check out ` :h rest-nvim.config ` for documentation.
12187
12288``` lua
89+ --- rest.nvim default configuration
90+ --- @class rest.Config
12391local default_config = {
124- env_pattern = " \\ .env$" ,
125- env_edit_command = " tabedit" ,
126- encode_url = true ,
127- skip_ssl_verification = false ,
92+ --- @type table<string , fun (): string> Table of custom dynamic variables
12893 custom_dynamic_variables = {},
129- logs = {
130- level = " info " ,
131- save = true ,
132- } ,
133- result = {
134- split = {
135- horizontal = false ,
136- in_place = false ,
137- stay_in_current_window_after_split = true ,
94+ --- @class rest.Config.Request
95+ request = {
96+ --- @type boolean Skip SSL verification , useful for unknown certificates
97+ skip_ssl_verification = false ,
98+ --- Default request hooks
99+ --- @class rest.Config.Request.Hooks
100+ hooks = {
101+ --- @type boolean Encode URL before making request
102+ encode_url = true ,
138103 },
139- behavior = {
104+ },
105+ --- @class rest.Config.Response
106+ response = {
107+ --- @class rest.Config.Response.Hooks
108+ hooks = {
109+ --- @type boolean Decode the request URL segments on response UI to improve readability
140110 decode_url = true ,
141- show_info = {
142- url = true ,
143- headers = true ,
144- http_info = true ,
145- curl_command = true ,
146- },
111+ --- @type boolean Format the response body
112+ format = true ,
113+ },
114+ --- @type table<string,RestResultFormatter>
115+ formatters = {
116+ json = " jq" ,
117+ html = function (body )
118+ if vim .fn .executable (" tidy" ) == 0 then
119+ return body , { found = false , name = " tidy" }
120+ end
121+ -- stylua: ignore
122+ local fmt_body = vim .fn .system ({
123+ " tidy" ,
124+ " -i" ,
125+ " -q" ,
126+ " --tidy-mark" , " no" ,
127+ " --show-body-only" , " auto" ,
128+ " --show-errors" , " 0" ,
129+ " --show-warnings" , " 0" ,
130+ " -" ,
131+ }, body ):gsub (" \n $" , " " )
132+
133+ return fmt_body , { found = true , name = " tidy" }
134+ end ,
135+ },
136+ },
137+ --- @class rest.Config.Clients
138+ clients = {
139+ --- @class rest.Config.Clients.Curl
140+ curl = {
141+ --- Statistics to be shown, takes cURL's `--write-out` flag variables
142+ --- See `man curl` for `--write-out` flag
143+ --- @type table<string,RestStatisticsStyle>
147144 statistics = {
148- enable = true ,
149- --- @see https ://curl.se /libcurl /c /curl_easy_getinfo.html
150- stats = {
151- { " total_time" , title = " Time taken:" },
152- { " size_download_t" , title = " Download size:" },
153- },
154- },
155- formatters = {
156- json = " jq" ,
157- html = function (body )
158- if vim .fn .executable (" tidy" ) == 0 then
159- return body , { found = false , name = " tidy" }
160- end
161- local fmt_body = vim .fn .system ({
162- " tidy" ,
163- " -i" ,
164- " -q" ,
165- " --tidy-mark" , " no" ,
166- " --show-body-only" , " auto" ,
167- " --show-errors" , " 0" ,
168- " --show-warnings" , " 0" ,
169- " -" ,
170- }, body ):gsub (" \n $" , " " )
171-
172- return fmt_body , { found = true , name = " tidy" }
173- end ,
145+ time_total = { winbar = " take" , title = " Time taken" },
146+ size_download = { winbar = " size" , title = " Download size" },
174147 },
175148 },
149+ },
150+ --- @class rest.Config.Cookies
151+ cookies = {
152+ --- @type boolean Whether enable cookies support or not
153+ enable = true ,
154+ --- @type string Cookies file path
155+ path = vim .fs .joinpath (vim .fn .stdpath (" data" ) --[[ @as string]] , " rest-nvim.cookies" )
156+ },
157+ --- @class rest.Config.Env
158+ env = {
159+ --- @type boolean
160+ enable = true ,
161+ --- @type string
162+ pattern = " %.env.*"
163+ },
164+ --- @class rest.Config.UI
165+ ui = {
166+ --- @type boolean Whether to set winbar to result panes
167+ winbar = true ,
168+ --- @class rest.Config.UI.Keybinds
176169 keybinds = {
170+ --- @type string Mapping for cycle to previous result pane
177171 prev = " H" ,
172+ --- @type string Mapping for cycle to next result pane
178173 next = " L" ,
179174 },
180175 },
176+ --- @class rest.Config.Highlight
181177 highlight = {
178+ --- @type boolean Whether current request highlighting is enabled or not
182179 enable = true ,
180+ --- @type number Duration time of the request highlighting in milliseconds
183181 timeout = 750 ,
184182 },
185183}
@@ -197,52 +195,39 @@ ensure_installed = { "lua", "xml", "http", "json", "graphql" }
197195
198196Or manually run ` :TSInstall lua xml http json graphql ` .
199197
200- ## Keybindings
201-
202- By default ` rest.nvim ` does not have any key mappings so you will not have
203- conflicts with any of your existing ones.
204-
205- However, ` rest.nvim ` exposes a ` :Rest ` command in HTTP files that you can use to create your
206- keybinds easily. For example:
207-
208- ``` lua
209- keybinds = {
210- {
211- " <localleader>rr" , " <cmd>Rest run<cr>" , " Run request under the cursor" ,
212- },
213- {
214- " <localleader>rl" , " <cmd>Rest run last<cr>" , " Re-run latest request" ,
215- },
216- }
217- ```
218-
219- You can still also use the legacy ` <Plug>RestNvim ` commands for mappings:
220- - ` <Plug>RestNvim ` , run the request under the cursor
221- - ` <Plug>RestNvimLast ` , re-run the last request
222-
223- > [ !NOTE]
224- >
225- > 1 . ` <Plug>RestNvimPreview ` has been removed, as we can no longer implement it with the current
226- > cURL implementation.
227- >
228- > 2 . The legacy ` <Plug> ` mappings will raise a deprecation warning suggesting you to switch to
229- > the ` :Rest ` command, as they are going to be completely removed in the next version.
230-
231198## Usage
232199
233200Create a new http file or open an existing one and place the cursor over the
234201request and run the <kbd >: Rest run</kbd > command.
235202
236203> [ !NOTE]
237204>
238- > 1 . You can find examples of use in the [ tests ] ( ./tests ) directory.
205+ > 1 . You can find examples of use in the [ spec/examples ] ( ./spec/examples ) directory.
239206>
240207> 2 . ` rest.nvim ` supports multiple HTTP requests in one file. It selects the
241208> request in the current cursor line, no matters the position as long as
242209> the cursor is on a request tree-sitter node.
243210
211+ ## Keybindings
212+
213+ By default ` rest.nvim ` does not have any key mappings except the result buffers so you will not have
214+ conflicts with any of your existing ones.
215+
216+ ## Commands
244217
245- ---
218+ | User Command | Behavior |
219+ | ------------------------| ------------------------------------------------------|
220+ | ` :Rest open ` | Open result pane |
221+ | ` :Rest run ` | Run request under the cursor |
222+ | ` :Rest run {name} ` | Run request with name ` {name} ` |
223+ | ` :Rest last ` | Run last request |
224+ | ` :Rest logs ` | Edit logs file |
225+ | ` :Rest cookies ` | Edit cookies file |
226+ | ` :Rest env show ` | Show dotenv file registered to current ` .http ` file |
227+ | ` :Rest env select ` | Select & register ` .env ` file with ` vim.ui.select() ` |
228+ | ` :Rest env set {path} ` | Register ` .env ` file to current ` .http ` file |
229+
230+ ## Extensions
246231
247232### Telescope Extension
248233
@@ -256,56 +241,20 @@ require("telescope").load_extension("rest")
256241require (" telescope" ).extensions .rest .select_env ()
257242```
258243
259- If running Ubuntu or Debian based systems you might need to run ` ln -s $(which fdfind) ~/.local/bin/fd ` to get extension to work. This is becuase extension runs the [ fd] ( https://github.com/sharkdp/fd?tab=readme-ov-file#installation ) command.
260-
261244Here is a preview of the extension working :)
262245
263246![ telescope rest extension demo] ( https://github.com/rest-nvim/rest.nvim/assets/36456999/a810954f-b45c-44ee-854d-94039de8e2fc )
264247
265- ### Mappings
248+ #### Mappings
266249
267250- <kbd >Enter</kbd >: Select Env file
268251- <kbd >Ctrl + O</kbd >: Edit Env file
269252
270- ### Config
271-
272- - ` env_pattern ` : For env file pattern
273- - ` env_edit_command ` : For env file edit command
274-
275-
276- ### Select environment alternative
277-
278- If you are not using telescope, this custom keybind can let you select an environment
279-
280- ``` lua
281- vim .keymap .set (' n' , ' ,q' , function ()
282- local pattern = _G ._rest_nvim .env_pattern
283- local command = string.format (" fd -HI '%s'" , pattern )
284- local result = io.popen (command ):read (' *a' )
285-
286- local env_list = {}
287- for line in result :gmatch (' [^\r\n ]+' ) do
288- table.insert (env_list , line )
289- end
290-
291- local rest_functions = require (' rest-nvim.functions' )
292-
293- vim .ui .select (env_list , {
294- prompt = ' Select env file ' ,
295- format_item = function (item )
296- return item
297- end ,
298- }, function (choice )
299- if choice == nil then
300- return
301- end
302- rest_functions .env (' set' , choice )
303- end )
304- end , { desc = ' [q]uery envs' })
305- ```
253+ #### Config
306254
255+ - ` config.env.pattern ` : For env file pattern (lua-pattern)
307256
308- ## Lualine
257+ ### Lualine Component
309258
310259We also have lualine component to get what env file you select!
311260
@@ -353,9 +302,8 @@ Here is a preview of the component working :)
353302> semantic versioning and these help with automatic releases, please use this type of convention
354303> when submitting changes to the project.
355304
356- Tests can be ran via ` make test ` . You must have ` luarocks ` installed and ` lua5.1 ` or ` luajit ` to
357- install dependencies. The test runner through ` make test ` will automatically install all required
358- dependencies.
305+ Tests can be ran via ` make test ` . You must have ` luarocks ` installed to install dependencies. The
306+ test runner through ` make test ` will automatically install all required dependencies.
359307
360308## Related software
361309
0 commit comments