Skip to content

Request json don´t formatting #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rcraftzy opened this issue Oct 15, 2022 · 1 comment
Closed

Request json don´t formatting #143

rcraftzy opened this issue Oct 15, 2022 · 1 comment

Comments

@rcraftzy
Copy link

rcraftzy commented Oct 15, 2022

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,
}
@peterfication
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants