Skip to content

Commit 4751980

Browse files
docs: modularize rest.Client
1 parent 968c15b commit 4751980

File tree

11 files changed

+125
-8
lines changed

11 files changed

+125
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ docgen:
1616
lemmy-help lua/rest-nvim/config/init.lua > doc/rest-nvim-config.txt
1717
lemmy-help lua/rest-nvim/cookie_jar.lua > doc/rest-nvim-cookies.txt
1818
lemmy-help lua/rest-nvim/script.lua > doc/rest-nvim-script.txt
19-
lemmy-help lua/rest-nvim/api.lua lua/rest-nvim/ui/result.lua lua/rest-nvim/utils.lua > doc/rest-nvim-api.txt
19+
lemmy-help lua/rest-nvim/api.lua lua/rest-nvim/client/init.lua lua/rest-nvim/ui/result.lua lua/rest-nvim/utils.lua > doc/rest-nvim-api.txt
2020
lemmy-help lua/rest-nvim/client/curl/cli.lua lua/rest-nvim/client/curl/utils.lua > doc/rest-nvim-client-curl.txt

doc/rest-nvim-api.txt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,69 @@ api.register_rest_subcommand({name}, {cmd})
4545
{cmd} (RestCmd)
4646

4747

48+
==============================================================================
49+
rest.nvim client module *rest-nvim.client*
50+
51+
52+
Mainly about `rest.Client` type requirements
53+
54+
55+
rest.Client *rest.Client*
56+
Client to send request
57+
58+
59+
client:request({req}) *client:request*
60+
Sends request and return the response asynchronously
61+
62+
Parameters: ~
63+
{req} (rest.Request)
64+
65+
Returns: ~
66+
(nio.control.Future) Future containing `rest.Response`
67+
68+
69+
==============================================================================
70+
rest.nvim result UI module *rest-nvim.ui.result*
71+
72+
73+
rest.nvim result UI implmentation
74+
75+
76+
rest.UIData *rest.UIData*
77+
data used to render the UI
78+
79+
80+
ui.stat_winbar() *ui.stat_winbar*
81+
Winbar component showing response statistics
82+
83+
Returns: ~
84+
(string)
85+
86+
87+
ui.is_open() *ui.is_open*
88+
Check if UI window is shown in current tabpage
89+
90+
Returns: ~
91+
(boolean)
92+
93+
94+
ui.enter({winnr}) *ui.enter*
95+
96+
Parameters: ~
97+
{winnr} (integer)
98+
99+
100+
ui.clear() *ui.clear*
101+
Clear the UI
102+
103+
104+
ui.update({new_data}) *ui.update*
105+
Update data and rerender the UI
106+
107+
Parameters: ~
108+
{new_data} (rest.UIData)
109+
110+
48111
==============================================================================
49112
rest.nvim utilities *rest-nvim.utils*
50113

doc/rest-nvim-client-curl.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ rest.nvim cURL cli client *rest-nvim.client.curl.cli*
77

88

99
curl.request({request}) *curl.request*
10-
returns future containing Result
10+
Send request via `curl` cli
1111

1212
Parameters: ~
1313
{request} (rest.Request) Request data to be passed to cURL
1414

1515
Returns: ~
16-
(nio.control.Future) future containing rest.Response
16+
(nio.control.Future) Future containing rest.Response
1717

1818

1919
utils.curl_error({code}) *utils.curl_error*

doc/rest-nvim-commands.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ rest.nvim commands *rest-nvim.commands*
2929
env set {path} Register environment file to current `.http` file.
3030
`path` should be relative to Neovim's cwd
3131

32-
NOTE: All `:Rest` commands opening new window supports |command-modifiers|.
32+
NOTE: All `:Rest` commands opening new window support |command-modifiers|.
3333
For example, you can run `:hor Rest open` to open result pane in horizontal
3434
split
3535

lua/rest-nvim/client/curl/cli.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ function builder.build(req)
300300
return vim.iter(args):flatten(math.huge):totable()
301301
end
302302

303-
---returns future containing Result
303+
---Send request via `curl` cli
304304
---@param request rest.Request Request data to be passed to cURL
305-
---@return nio.control.Future future future containing rest.Response
305+
---@return nio.control.Future future Future containing rest.Response
306306
function curl.request(request)
307307
local progress_handle = progress.handle.create({
308308
title = "Fetching",

lua/rest-nvim/client/curl/libcurl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---@mod rest-nvim.client.curl.libcurl rest.nvim cURL client
1+
---@mod rest-nvim.client.curl.libcurl rest.nvim cURL client using libcurl (deprecated)
22
---
33
---@brief [[
44
---

lua/rest-nvim/client/curl_cli.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
local curl_cli = require("rest-nvim.client.curl.cli")
2+
3+
---@type rest.Client
4+
local client = {
5+
request = curl_cli.request
6+
}
7+
8+
return client

lua/rest-nvim/client/init.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---@mod rest-nvim.client rest.nvim client module
2+
---
3+
---@brief [[
4+
---
5+
--- Mainly about `rest.Client` type requirements
6+
---
7+
---@brief ]]
8+
9+
---Client to send request
10+
---@class rest.Client
11+
local client = {}
12+
13+
---Sends request and return the response asynchronously
14+
---@param req rest.Request
15+
---@return nio.control.Future future Future containing `rest.Response`
16+
function client:request(req)
17+
local future = require("nio").control.future()
18+
vim.print(req)
19+
return future
20+
end
21+
22+
return client

lua/rest-nvim/request.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,20 @@ local rest_nvim_last_request = nil
3131
---@param req rest.Request
3232
local function run_request(req)
3333
logger.debug("run_request")
34-
local client = require("rest-nvim.client.curl.cli")
34+
---@type rest.Client
35+
local client
36+
if req.method == "WEBSOCKET" then
37+
logger.error("method: websocket isn't supported yet")
38+
return
39+
elseif req.method == "GRPC" then
40+
logger.error("method: grpc isn't supported yet")
41+
return
42+
elseif req.method == "GRAPHQL" then
43+
logger.error("method: graphql isn't supported yet")
44+
return
45+
else
46+
client = require("rest-nvim.client.curl.cli")
47+
end
3548
rest_nvim_last_request = req
3649

3750
_G.rest_request = req

lua/rest-nvim/ui/result.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
---@mod rest-nvim.ui.result rest.nvim result UI module
2+
---
3+
---@brief [[
4+
---
5+
--- rest.nvim result UI implmentation
6+
---
7+
---@brief ]]
8+
19
local ui = {}
210

311
local config = require("rest-nvim.config")
@@ -19,6 +27,7 @@ local function syntax_highlight(buffer, filetype)
1927
end
2028
end
2129

30+
---data used to render the UI
2231
---@class rest.UIData
2332
local data = {
2433
---@type rest.Request?

0 commit comments

Comments
 (0)