Vim-rest-console
lastmod 2024-07-18created 2021-03-134 edits
A REST console for Vim.
File type / extension
Create a file with the .rest extension and open it in Vim to edit it,
or in an empty buffer, enter rest editing mode with the :set filetype=rest command.
In the buffer, write the request's host, headers, method and relative path, and body, one per line. Headers and body can be omitted.
Syntax
A VRC buffer can have one or many REST request blocks.
A "request block" contains a "host," "optional cUrl options," "optional headers," "query," and an "optional request body" (usually used by POST). A block is defined as follows.
# host
http[s]://domain[:port]
[optional cUrl options]
[optional headers]
# query
POST /path/to/resource
[optional request body]
The global section is separated from the rest of the sections by two dashes '--' and can contain a default host, optional default cUrl options (buffer scope), and optional default headers. These values are always included in each request.
# Global definitions.
// Default host.
https://domain[:port]/...
// Default (buffer scope) cUrl options.
-L
--connect-timeout 10
// Default headers.
Accept: application/json
X-Header: Custom Data
--
# Request block that uses default values from the global section.
--
GET /some/query
# Request block that specifies its own host and extra headers.
// Local host.
https://example.net:9200
// Local cUrl opts.
-k
--ipv4
// This cUrl option overwrites the one in the global section.
--connect-timeout 30
-b /path/to/cookie
-c /path/to/cookie
// Extra headers.
Xtra-Header: Some Extra.
// This header will overwrite the one in the global section.
X-Header: New Data
POST /service
var1=value
Comments
A comment starts with '#' or '//' and must be on its own line. The following is an example of a VRC buffer with multiple request blocks.
Example
http://127.0.0.1:3000
GET /api/users/bakyeono
http://127.0.0.1:3000
POST /api/languages/ansi-common-lisp
http://127.0.0.1:3000
PUT /api/resources/1789
http://127.0.0.1:3000
Accepts: application/text; charset=utf-8
PUT /api/chat
{
"message": "hello"
}
After writing this, place the cursor on the message you want to request and press <C-j>; the request is sent and the result is printed to a temporary buffer.