rest.nvim
rest.nvim copied to clipboard
Request json don´t formatting
I use the config for default and have installed jq for formatting json ¿Why don´t formatting json?
If I user jq in curl it works
local ok, rest = pcall(require, "rest-nvim")
if not ok then
return
end
rest.setup {
-- Open request results in a horizontal split
result_split_horizontal = false,
-- Keep the http file buffer above|left when split horizontal|vertical
result_split_in_place = false,
-- Skip SSL verification, useful for unknown certificates
skip_ssl_verification = false,
-- Encode URL before making request
encode_url = true,
-- Highlight request on run
highlight = {
enabled = true,
timeout = 150,
},
result = {
-- toggle showing URL, HTTP info, headers at top the of result window
show_url = true,
show_http_info = true,
show_headers = true,
-- executables or functions for formatting response body [optional]
-- set them to nil if you want to disable them
formatters = {
json = "jq",
html = function(body)
return vim.fn.system({ "tidy", "-i", "-q", "-" }, body)
end,
},
},
-- Jump to request line on run
jump_to_request = false,
env_file = ".env",
custom_dynamic_variables = {},
yank_dry_run = true,
}
You need to check the content type for your request. I had the same issue and my problem was that the content type was application/vnd.api+json
from JSON API and so the I had to add a formatter for vnd
:
local ok, rest = pcall(require, "rest-nvim")
if not ok then
return
end
rest.setup {
...
result = {
...
formatters = {
json = "jq",
vnd = "jq",
html = function(body)
return vim.fn.system({ "tidy", "-i", "-q", "-" }, body)
end,
},
},
}
So it might be a bug in how the content type function analyzes the content type, but has the fix is to just add another formatter in the config, I think the content type matcher shouldn't be adjusted. Maybe an adjustment in the config section of the README is necessary.