@@ -27,6 +27,8 @@ function functions.exec(scope)
2727 })
2828
2929 local api = require (" rest-nvim.api" )
30+ local env_vars = require (" rest-nvim.parser.env_vars" )
31+
3032 local logger = _G ._rest_nvim .logger
3133 local ok , client = pcall (require , " rest-nvim.client." .. _G ._rest_nvim .client )
3234 if not ok then
@@ -60,6 +62,17 @@ function functions.exec(scope)
6062
6163 utils .highlight (0 , req .start , req .end_ , api .namespace )
6264
65+ -- Set up a _rest_nvim_req_data Lua global table that holds the parsed request
66+ -- so the values can be modified from the pre-request hooks
67+ _G ._rest_nvim_req_data = req
68+ -- Load environment variables from the env file
69+ env_vars .read_file (true )
70+ -- Run pre-request hooks
71+ api .exec_pre_request_hooks ()
72+ -- Clean the _rest_nvim_req_data global after running the pre-request hooks
73+ -- as the req table will remain modified
74+ _G ._rest_nvim_req_data = nil
75+
6376 if found_nio then
6477 req_results = nio
6578 .run (function ()
@@ -82,6 +95,17 @@ function functions.exec(scope)
8295 else
8396 utils .highlight (0 , req .start , req .end_ , api .namespace )
8497
98+ -- Set up a _rest_nvim_req_data Lua global table that holds the parsed request
99+ -- so the values can be modified from the pre-request hooks
100+ _G ._rest_nvim_req_data = req
101+ -- Load environment variables from the env file
102+ env_vars .read_file (true )
103+ -- Run pre-request hooks
104+ api .exec_pre_request_hooks ()
105+ -- Clean the _rest_nvim_req_data global after running the pre-request hooks
106+ -- as the req table will remain modified
107+ _G ._rest_nvim_req_data = nil
108+
85109 if found_nio then
86110 req_results = nio
87111 .run (function ()
@@ -94,15 +118,24 @@ function functions.exec(scope)
94118 end
95119 end
96120
121+ -- We should not be trying to show a result or evaluate code if the request failed
97122 if not vim .tbl_isempty (req_results ) then
98- -- We should not be trying to show a result if the request failed
99123 local result_buf = result .get_or_create_buf ()
100124 result .write_res (result_buf , req_results )
101125
102126 -- Load the script variables
103127 if req_results .script ~= nil or not req_results .script == " " then
104128 script_vars .load (req_results .script , req_results )
105129 end
130+
131+ -- Set up a _rest_nvim_res_data Lua global table that holds the request results
132+ -- so the values can be modified from the post-request hooks
133+ _G ._rest_nvim_res_data = req_results
134+ -- Run post-request hooks
135+ api .exec_post_request_hooks ()
136+ -- Clean the _rest_nvim_res_data global after running the post-request hooks
137+ -- as the req_results table will remain modified
138+ _G ._rest_nvim_res_data = nil
106139 end
107140end
108141
0 commit comments