heilgar/nvim-http-client

github github
programming-languages-supportweb-development
stars 12
issues 0
subscribers 1
forks 2
CREATED

2024-09-09

UPDATED

9 days ago


Neovim HTTP Request Plugin

Tests

A Neovim plugin for running HTTP requests directly from .http files, with support for environment variables. Inspired by the IntelliJ HTTP Client, this plugin brings similar functionality to Neovim in an easy-to-install and easy-to-use package.

The core goal is to ensure compatibility with .http files from IntelliJ or VSCode, allowing them to run smoothly in Neovim and vice-versa.

Development is ongoing, with new features added as needed or when time permits.

Table of Contents

Installation

This plugin is designed to be installed with Lazy.nvim.

Quick Start (Copy & Paste)

Copy this complete configuration into your Lazy.nvim setup:

{
    "heilgar/nvim-http-client",
    dependencies = {
        "nvim-lua/plenary.nvim",
        "hrsh7th/nvim-cmp", -- Optional but recommended for enhanced autocompletion
        "nvim-telescope/telescope.nvim", -- Optional for better environment selection
    },
    event = "VeryLazy",
    ft = { "http", "rest" },
    config = function()
        require("http_client").setup({
            -- Default configuration (works out of the box)
            default_env_file = '.env.json',
            request_timeout = 30000,
            split_direction = "right",
            create_keybindings = true,
            
            -- Profiling (timing metrics for requests)
            profiling = {
                enabled = true,
                show_in_response = true,
                detailed_metrics = true,
            },
            
            -- Default keybindings (can be customized)
            keybindings = {
                select_env_file = "<leader>hf",
                set_env = "<leader>he",
                run_request = "<leader>hr",
                stop_request = "<leader>hx",
                toggle_verbose = "<leader>hv",
                toggle_profiling = "<leader>hp",
                dry_run = "<leader>hd",
                copy_curl = "<leader>hc",
                save_response = "<leader>hs",
            },
        })
        
        -- Set up Telescope integration if available
        if pcall(require, "telescope") then
            require("telescope").load_extension("http_client")
        end
    end
}

Note about Autocompletion: If you have nvim-cmp installed, HTTP-specific autocompletion sources are automatically registered and configured for .http and .rest files. You don't need any additional configuration! The plugin provides completion for HTTP methods, headers, environment variables, and content types out of the box.

For full configuration options, see Configuration Documentation.

Usage

  1. Create a .http file with your HTTP requests.
  2. Create a .env.json file with your environments.
  3. Use the provided commands to select an environment and run requests.

Commands

  • :HttpEnvFile: Select an environment file (.env.json) to use
  • :HttpEnv: Select an environment from the current environment file
  • :HttpRun: Run the HTTP request under the cursor
  • :HttpRunAll: Run all HTTP requests in the current file
  • :HttpStop: Stop the currently running HTTP request
  • :HttpVerbose: Toggle verbose mode for debugging
  • :HttpProfiling: Toggle request profiling
  • :HttpDryRun: Perform a dry run of the request under the cursor
  • :HttpCopyCurl: Copy the curl command for the HTTP request under the cursor
  • :HttpSaveResponse: Save the response body to a file

Keybindings

The plugin comes with the following default keybindings (if create_keybindings is set to true):

  • <leader>hf: Select environment file
  • <leader>he: Set current environment
  • <leader>hr: Run HTTP request under cursor
  • <leader>hx: Stop running HTTP request
  • <leader>hv: Toggle verbose mode
  • <leader>hp: Toggle request profiling
  • <leader>hd: Perform dry run
  • <leader>hc: Copy curl command
  • <leader>hs: Save response to file

Features

  • Run HTTP requests from .http files
  • Support for environment variables
  • Easy switching between different environments
  • Non-blocking requests
  • Pretty-printed response display in a separate buffer
  • Automatic formatting for JSON and XML responses
  • Syntax highlighting for .http files and response buffers
  • Verbose mode for debugging
  • Dry run capability for request inspection
  • Request profiling with detailed timing metrics
  • Telescope integration for environment selection
  • Autocompletion for HTTP methods, headers and environment variables
  • Compatible with JetBrains HTTP Client and VSCode Restclient

Feature Comparison

Below is a comparison between this plugin and JetBrains HTTP Client, showing what's already implemented and what's planned for future releases:

Feature Status Notes
Basic HTTP requests All HTTP methods, headers, body
Environment variables Including private env files
Response formatting JSON, XML with syntax highlighting
Post-request scripts Response handlers with > {% ... %} syntax
Variable autocompletion Environment variables, headers, methods
Request profiling Detailed timing metrics
Response history Last 10 responses preserved
Dry run & curl export Preview requests before sending
Custom SSL certificate handling Self-signed certificate support
Request chaining ⚠️ Basic support via global variables
Authentication helpers ⚠️ Basic support through headers
Response headers folding ⚠️ Basic support via Neovim folds
Cookie management Planned
Pre-request scripts High priority - planned
File upload handling High priority - planned
GraphQL support Planned
Redirects configuration Planned
WebSocket/gRPC support Planned
Response schema validation Planned
Response diff comparison Planned
Request collections Planned
Generated client code Planned
Response testing/assertions Planned
Proxy configuration Planned
Request rate limiting Planned
Batch request processing Planned
Request signing (AWS, etc.) Planned
OpenAPI/Swagger integration Multiple features planned:
  - Direct execution from Swagger files High priority - Run requests directly from .yaml/.json OpenAPI files
  - Import from OpenAPI specs Generate .http files from spec definitions
  - Generate OpenAPI specs Create specs from existing requests
  - API documentation viewer Visualize API documentation within Neovim
Postman compatibility Multiple features planned:
  - Direct execution from Postman files Run requests directly from Postman collection files
  - Import Postman collections Convert Postman requests to .http format
  - Import Postman environments Convert to .env.json format
  - Export to Postman format For sharing with Postman users

Legend:

  • ✅ = Fully implemented
  • ⚠️ = Partially implemented
  • ❌ = Not yet implemented

Documentation

For detailed documentation on specific features, see:

You can also access the plugin's help documentation by running :h http_client in Neovim.

Screenshots

Dry Run

Dry Run This screenshot shows the dry run feature, which allows you to preview the HTTP request before sending it.

Environment Selection

Environment Selection This image demonstrates the environment selection within a chosen .env.json file, allowing you to switch between different configurations.

HTTP Response

HTTP Response This screenshot displays how HTTP responses are presented after executing a request.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Read our Contributing Guidelines.
  2. Ensure you've updated the CHANGELOG.md file with your changes.

License

This project is licensed under the MIT License. See the LICENSE file for details.