rest.nvim
rest.nvim copied to clipboard
Posting forms is not working
posting forms is not working
example:
POST http://localhost:8080/upload
-F "uploads=@/home/user/my_file.md"
{}
this is translated to the following curl command using RestNvimPreview (which works):
curl -sSL --compressed -X 'POST' -F "uploads=@/home/user/my_file.md" 'http://localhost:8080/upload'
but running it using RestNvim returns this error
Error executing luv callback:
...site/pack/packer/start/plenary.nvim/lua/plenary/curl.lua:260: post http://localhost:8080/upload - curl error exit_code=26 stderr={ "curl: (26) Failed to open/read local data from file/application" }
stack traceback:
[C]: in function 'error'
...site/pack/packer/start/plenary.nvim/lua/plenary/curl.lua:260: in function '_user_on_exit'
.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:240: in function '_shutdown'
.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:46: in function <.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:37>
taking a look at the table that is being sent to plenary's curl.lua I found this
{
body = vim.empty_dict(),
bufnr = 1,
callback = <function 1>,
dry_run = false,
end_line = 16,
headers = {},
method = "post",
raw = { '-F "uploads=@/home/kanon/my_file.md"' },
start_line = 11,
url = "http://localhost:8080/upload"
}
the option is being sent in the raw
key, but plenary also has the option of receiving a form
key, so I'm guessing sending it there would help?
just tested my theory adding this line to the bottom of the M.curl_cmd
function and it worked
opts.form = { uploads = "@/home/kanon/my_file.md" }
so it looks like this:
opts.callback = vim.schedule_wrap(create_callback(opts.method, opts.
opts.form = { uploads = "@/home/kanon/my_file.md" }
curl[opts.method](opts)
Closing this due to v3 release of both rest.nvim and tree-sitter-http.
Now http parser supports form data, and rest.nvim supports form-urlencoded
multipart-form-data
will be supported later with RFC standard.