14
14
15
15
</div >
16
16
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
-
21
17
---
22
18
23
19
A 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
52
48
### Dependencies
53
49
54
50
- 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 `
57
52
- Optional [ can be changed, see config below] ( #default-configuration )
58
53
- ` jq ` (to format JSON output)
59
54
- ` tidy ` (to format HTML output)
60
55
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
-
68
56
### [ rocks.nvim] ( https://github.com/nvim-neorocks/rocks.nvim ) (recommended)
69
57
70
58
``` vim
@@ -74,39 +62,17 @@ CLI. For more information on this, please see this [blog post](https://amartin.c
74
62
### [ lazy.nvim] ( https://github.com/folke/lazy.nvim )
75
63
76
64
``` lua
77
- {
78
- " vhyrro/luarocks.nvim" ,
79
- priority = 1000 ,
80
- config = true ,
81
- opts = {
82
- rocks = { " lua-curl" , " nvim-nio" , " mimetypes" , " xml2lua" }
83
- }
84
- },
85
65
{
86
66
" rest-nvim/rest.nvim" ,
87
- ft = " http" ,
88
- dependencies = { " luarocks.nvim" },
89
- config = function ()
90
- require (" rest-nvim" ).setup ()
91
- end ,
92
67
}
93
68
```
94
69
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
-
101
70
### [ packer.nvim] ( https://github.com/wbthomason/packer.nvim )
102
71
103
72
``` lua
104
73
use {
105
74
" 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" },
110
76
}
111
77
```
112
78
@@ -120,66 +86,98 @@ get a good experience during autocompletion :)
120
86
> You can also check out ` :h rest-nvim.config ` for documentation.
121
87
122
88
``` lua
89
+ --- rest.nvim default configuration
90
+ --- @class rest.Config
123
91
local 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
128
93
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 ,
138
103
},
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
140
110
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>
147
144
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" },
174
147
},
175
148
},
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
176
169
keybinds = {
170
+ --- @type string Mapping for cycle to previous result pane
177
171
prev = " H" ,
172
+ --- @type string Mapping for cycle to next result pane
178
173
next = " L" ,
179
174
},
180
175
},
176
+ --- @class rest.Config.Highlight
181
177
highlight = {
178
+ --- @type boolean Whether current request highlighting is enabled or not
182
179
enable = true ,
180
+ --- @type number Duration time of the request highlighting in milliseconds
183
181
timeout = 750 ,
184
182
},
185
183
}
@@ -197,52 +195,39 @@ ensure_installed = { "lua", "xml", "http", "json", "graphql" }
197
195
198
196
Or manually run ` :TSInstall lua xml http json graphql ` .
199
197
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
-
231
198
## Usage
232
199
233
200
Create a new http file or open an existing one and place the cursor over the
234
201
request and run the <kbd >: Rest run</kbd > command.
235
202
236
203
> [ !NOTE]
237
204
>
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.
239
206
>
240
207
> 2 . ` rest.nvim ` supports multiple HTTP requests in one file. It selects the
241
208
> request in the current cursor line, no matters the position as long as
242
209
> the cursor is on a request tree-sitter node.
243
210
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
244
217
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
246
231
247
232
### Telescope Extension
248
233
@@ -256,56 +241,20 @@ require("telescope").load_extension("rest")
256
241
require (" telescope" ).extensions .rest .select_env ()
257
242
```
258
243
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
-
261
244
Here is a preview of the extension working :)
262
245
263
246
![ telescope rest extension demo] ( https://github.com/rest-nvim/rest.nvim/assets/36456999/a810954f-b45c-44ee-854d-94039de8e2fc )
264
247
265
- ### Mappings
248
+ #### Mappings
266
249
267
250
- <kbd >Enter</kbd >: Select Env file
268
251
- <kbd >Ctrl + O</kbd >: Edit Env file
269
252
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
306
254
255
+ - ` config.env.pattern ` : For env file pattern (lua-pattern)
307
256
308
- ## Lualine
257
+ ### Lualine Component
309
258
310
259
We also have lualine component to get what env file you select!
311
260
@@ -353,9 +302,8 @@ Here is a preview of the component working :)
353
302
> semantic versioning and these help with automatic releases, please use this type of convention
354
303
> when submitting changes to the project.
355
304
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.
359
307
360
308
## Related software
361
309
0 commit comments