A vim port of the VSCode Rest Client.
With a simple *.http
or *.rest
file in your project you can trigger API
requests and view the responses directly in vim.
Use your favorite plugin manager to install.
" vim-plug
Plug 'jecxjo/rest-client.vim'
Or install it manually:
Vim 8:
mkdir -p ~/.vim/pack/jecxjo/start
cd ~/.vim/pack/jecxjo/start
git clone https://github.com/jecxjo/rest-client.vim.git
vim -u NONE -c "helptags rest-client.vim/doc" -c q
Neovim:
mkdir -p ~/.config/nvim/pack/jecxjo/start
cd ~/.config/nvim/pack/jecxjo/start
git clone https://github.com/jecxjo/rest-client.vim.git
nvim -u NONE -c "helptags rest-client.vim/doc" -c q
Only dependencies are curl
and jq
.
- Send Requests with all methods
- Response Headers
- Configurable response output
- JSON Parsing
- Variables in API (local)
- Config File Variables
- Prompts
- Basic Auth
- Digest Auth
- API Specific config
- Cookie support (with configurable location)
- Form support
- Multi-part data support
- Process variables / guid / dotenv / randomInt / timestamps
- Curl specific settings
- Certs support
Create a simple text file containing your API requests.
# My API
###
# Hello World API
GET http://localhost:3000/hello?name=World
###
# Create User
POST http://localhost:3000/new-user
Content-Type: application/json
{
"name": "Alice",
"age": 30
}
Move your cursor to an API (between the ###
lines) and run :RestClient
. If the output is JSON and you want it cleaned run :RestClientJSON
.
You can also rerun the last API call made with :RestClientReRun
.
The plugin supports variables via the environment file http-client.env.json
. The format is as follows:
{
"local": {
"host": "http://localhost:3000"
},
"test": {
"host": "https://uat.example.com"
}
"prod": {
"host": "https://example.com"
}
}
In the API file you can reference the variables wrapping them in double curly braces.
###
# Hello World
GET {{host}}/hello?name=World
To pick the environment to use run :RestClient <env>
or RestClientJSON <env>
. To see what environments are available and what variables exist run :RestClientEnv
.
To use local variables start a line with @
in or above the API block.
###
@host = http://localhost:3000
GET {{host}}/api
The format is simple. Each API is between ###
or the end of file. Each API has the format:
METHOD URL
[<Header Name: Header Value>]
[<Body>]
Multiple headers can be added, one to each line.
The body for POST
and PUT
start after the first empty line after method/url and headers. If a file is being send the body should be < filename
###
# Upload File
POST {{host}}/Upload
< ./data.txt
There is also a syntax file for the API files. To enable add the following to your RC file:
au BufRead,BufNewFile *.http,*.rest set filetype=http
This plugin is inspirred by the VSCode Rest Client
BSD-3, see LICENSE