aboutsummaryrefslogtreecommitdiffstats
path: root/lua/plugins/rest.lua
blob: 2eca10260551c17a1156ad5f0e5b7aa961eaa978 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
return {
  "NTBBloodbath/rest.nvim",
  dependencies = { "nvim-lua/plenary.nvim" },
  ft = "http",
  config = function()
    local rest_nvim = require "rest-nvim"

    rest_nvim.setup {
      -- Open request results in a horizontal split
      result_split_horizontal = false,
      -- Skip SSL verification, useful for unknown certificates
      skip_ssl_verification = false,
      -- 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,
      },
      -- Jump to request line on run
      jump_to_request = false,
      env_file = ".env",
      custom_dynamic_variables = {},
      yank_dry_run = true,
    }

    vim.api.nvim_create_autocmd("FileType", {
      pattern = "http",
      callback = function()
        local buff = tonumber(vim.fn.expand "<abuf>", 10)
        vim.keymap.set(
          "n",
          "<leader>hn",
          rest_nvim.run,
          { noremap = true, buffer = buff, desc = "Run near http request" }
        )
        vim.keymap.set(
          "n",
          "<leader>hl",
          rest_nvim.last,
          { noremap = true, buffer = buff, desc = "Run last http resquest" }
        )
        vim.keymap.set("n", "<leader>hp", function()
          rest_nvim.run(true)
        end, { noremap = true, buffer = buff, desc = "Preview http curl" })
      end,
    })
  end,
}