Skip to content

This neovim plugin just do one thing: send http request under cursor and return the http response to you.

Notifications You must be signed in to change notification settings

sunn4room/httpc.nvim

Repository files navigation

Note

please read this link.

httpc.nvim

This neovim plugin just do one thing: send http request under cursor and return the http response to you.

-- lazy.nvim spec
return {
  "sunn4room/httpc.nvim",
  ft = "http",
  opts = {
    register = "_", -- the register used to hold the response
    animation = {
      spinner = { "|", "/", "-", "\\" },
      interval = 100,
    },
    magics = {
      -- processEnv = function(args) ... end,
      -- datetime = function(args) ... end,
      -- randomInt = function(args) ... end,
      -- timestamp = function(args) ... end,
      -- urlencode = function(args) ... end,
      -- ...
      -- usage: {{$<magic> <arg1> <arg2> <args3>}}
    },
    patterns = {
      -- json = "^application/.*json.*$",
      -- ...
      -- get lang from content-type for highlights.
    },
  },
}

Note

neovim doesn't recogize http ft by default.

vim.filetype.add {
  extension = {
    http = "http",
    rest = "http",
  },
}

features

  • Request parse.
    • method
    • url
    • http version
    • headers
    • body
    • external body
    • form
    • graphql
  • Spinner to indicate that request is running.
  • variable replacement.
    • Define variable inside http file.
    • Use magic lua function in variable replacement.
    • Read variable from environment files.
  • Response highlight.

usage

-- run request under cursor
require("httpc").run()

-- run request somewhere
require("httpc").run({ buf = 0, row = 0, col = 0 })

-- cancel the running request if any
require("httpc").cancel()

Q&A

Can I customize the spinner highlight group?

Yes, you can.

{
  animation = {
    spinner = {
      {
        { ">", "Comment" },
        { ">", "Comment" },
        { ">", "Comment" },
      },
      {
        { ">", "Special" },
        { ">", "Comment" },
        { ">", "Comment" },
      },
      {
        { ">", "Comment" },
        { ">", "Special" },
        { ">", "Comment" },
      },
      {
        { ">", "Comment" },
        { ">", "Comment" },
        { ">", "Special" },
      },
    },
  },
}

Can I use another variable during variable declaration?

Yes, you can.

@ORG=httpbin
@HOST={{ORG}}.org

###

GET https://{{HOST}}/get

How to include space character in arguments during magic replacement?

GET https://httpbin.org/get
Current-Datetime: {{$datetime %Y-%m-%d\ %H:%M:%S}}

How to special the env during reading variables from env files?

By default, httpc.nvim read variables from http-client.env.json and http-client.env.json.user with dev env.

vim.b.http_client_env = "prod"

About

This neovim plugin just do one thing: send http request under cursor and return the http response to you.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages