{"id":13479820,"url":"https://github.com/diepm/vim-rest-console","last_synced_at":"2025-03-27T10:30:47.088Z","repository":{"id":32760400,"uuid":"36351726","full_name":"diepm/vim-rest-console","owner":"diepm","description":"A REST console for Vim.","archived":false,"fork":false,"pushed_at":"2024-02-29T09:55:32.000Z","size":173,"stargazers_count":662,"open_issues_count":30,"forks_count":54,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-30T13:38:29.841Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Vim script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/diepm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-05-27T07:48:15.000Z","updated_at":"2024-10-27T03:40:02.000Z","dependencies_parsed_at":"2024-01-16T06:31:53.667Z","dependency_job_id":"924504d4-e53f-436f-adcf-2f8a027079b6","html_url":"https://github.com/diepm/vim-rest-console","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diepm%2Fvim-rest-console","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diepm%2Fvim-rest-console/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diepm%2Fvim-rest-console/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diepm%2Fvim-rest-console/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diepm","download_url":"https://codeload.github.com/diepm/vim-rest-console/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245826712,"owners_count":20678844,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T16:02:23.476Z","updated_at":"2025-03-27T10:30:46.842Z","avatar_url":"https://github.com/diepm.png","language":"Vim script","funding_links":[],"categories":["Vim Script","Vim script","Ferramentas"],"sub_categories":[],"readme":"# Vim REST Console (VRC)\n\n### 1. Introduction\n\n**VRC** is a Vim plug-in to help send requests to and display responses from\nRESTful services in Vim. It's useful for working with REST services that use\nJSON to exchange information between server and client such as ElasticSearch.\n\nVRC can also be used as a cURL client for simple needs such as getting a\nHTTP page response or posting to a form.\n\nRequirements:\n\n* cURL\n* Vim 7.4 (might work with the older Vim versions)\n\n### 2. Features\n\n* Execute REST request and display the response on a separate display buffer.\n* Make changing/adjusting request body easy.\n* Can have multiple REST request blocks per VRC buffer.\n* Can have multiple VRC buffers where they all share the same output buffer or\n  each can have its own output buffer.\n* Particularly useful for working with REST services that require the request\n  body to be sent in JSON such as ElasticSearch.\n* Syntax highlighting.\n* Supported verbs: GET, POST, PUT, HEAD, PATCH, OPTIONS, and TRACE.\n\n### 3. Installation\n\nVRC requires [cURL](http://curl.haxx.se/). It's tested with Vim 7.4 but might\nwork with the older versions.\n\nTo install using [pathogen.vim](https://github.com/tpope/vim-pathogen)\n\n    cd ~/.vim/bundle\n    git clone https://github.com/diepm/vim-rest-console.git\n\nTo install using [Vundle](https://github.com/gmarik/Vundle.vim)\n\n    \" Add this line to .vimrc\n    Plugin 'diepm/vim-rest-console'\n\nOther methods should work as well.\n\n### 4. Examples\n\nFor more examples, check out\n\nhttps://raw.githubusercontent.com/diepm/vim-rest-console/master/sample.rest\n\nthere is also an alternative version using global settings:\n\nhttps://raw.githubusercontent.com/diepm/vim-rest-console/master/sample_global.rest\n\nThe following examples assume that an ElasticSearch service is running at\nlocalhost. The pipe (`|`) indicates the current position of the cursor.\n\n#### 4.1 Single VRC Buffer\n\n* From the command line, run a new Vim instance.\n* Set the buffer `filetype` to `rest` by\n\n  ```\n  :set ft=rest\n  ```\n\n* Type in\n\n  ```\n  http://localhost:9200\n  GET /_cat/nodes?v|\n  ```\n\n* Hit the trigger key (`\u003cC-j\u003e` by default).\n* A new vertically split buffer will be shown to display the output.\n* Change the request block to (or add another one)\n\n  ```\n  http://localhost:9200\n  POST /testindex/testtype\n  {\n    \"key\": \"new key\",\n    \"value\": \"new value\"|\n  }\n  ```\n\n* Hit the trigger key with the cursor placed anywhere within this request block.\n* The display buffer will be updated with the new response.\n\n#### 4.2 Multiple VRC Buffers\n\nThis example continues the previous one.\n\n* Open a new VRC buffer in a new tab\n\n  ```\n  :tabe NewVrc.rest\n  ```\n\n* Since the new buffer has the extension `rest`, the VRC plug-in is active for\n  this one.\n* Set `b:vrc_output_buffer_name` of this buffer to `__NEW_VRC__`\n\n  ```\n  :let b:vrc_output_buffer_name = '__NEW_VRC__'\n  ```\n\n* Type in a request block such as\n\n  ```\n  http://localhost:9200\n  GET /testindex/_search?pretty|\n  ```\n\n* Hit the trigger key.\n* A new display buffer will be created showing the response.\n* Go back to the VRC buffer of the previous example (previous tab).\n* Try to execute an existing request block.\n* The corresponding display buffer will be updated.\n\n### 5. Usage\n\nThis plug-in is activated when Vim opens a buffer of type `rest`. This may be\na file with the extension `.rest` or a buffer with `filetype` explicitly set to\n`rest` by\n\n    :set ft=rest\n\nA **VRC buffer** can have one or many REST request blocks. A **request block**\ncontains a *host*, *optional cUrl options*, *optional headers*, *query*, and an\n*optional request body* (usually used by POST). A block is defined as follows.\n\n    # host\n    http[s]://domain[:port]\n\n    [optional cUrl options]\n\n    [optional headers]\n\n    # query\n    POST /path/to/resource\n    [optional request body]\n\nA comment starts with `#` or `//` and must be on its own line. The following\nis an example of a VRC buffer with multiple request blocks.\n\n    # GETting from resource.\n    http://example.com\n    GET /path/to/resource?key=value\n\n    # POSTing to an ElasticSearch service.\n    http://example.com/elasticsearch\n\n    // Specify optional headers.\n    Content-Type: application/json; charset=utf-8\n\n    POST /index/type?pretty\n    {\n        \"key\": \"a key\",\n        \"value\": \"a value\"\n    }\n\n    # Submitting a form.\n    https://example.net:8080\n\n    Accept: */*\n    Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n    Cache-Control: no-cache\n    Connection: keep-alive\n    Content-Type: application/x-www-form-urlencoded\n    Cookie: userId=ac32:dfbe:8f1a:249c; sid=cfb48e3d98fcb1\n    User-Agent: VRC\n\n    POST /form\n    var1=value of var1\u0026\n    var2=value of var2\n\nWhen the trigger key is called (`\u003cC-j\u003e` by default), VRC processes the request\nblock that the cursor stays within. The response is displayed in a new\nvertically split buffer. This output buffer is reused if it's already present.\n\nBy default, the display/output buffer is named `__REST_response__`. If there\nare multiple VRC buffers, they all share the same display buffer. To have a\nseparate output display for each VRC buffer, `b:vrc_output_buffer_name` can be\nset in the buffer scope.\n\n#### 5.1 cUrl Options\n\nA recent addition to VRC is the ability to specify cUrl options. These may be\nspecified by the VRC option `vrc_curl_opts` or declaring in the\n[global section](#52-global-definitions) of a REST buffer and request blocks.\n\nAll specified cUrl options are merged together when a cUrl command is built.\nFor the same keys (cUrl switch) specified at different scopes, the ones of the\nrequest blocks overwrite the ones in the global section then overwrite the\nones defined by `vrc_curl_opts`.\n\nFor the deprecated VRC options, they can be replaced by cUrl options. For\nexample, assuming they have been defined as follows.\n\n    let g:vrc_connect_timeout = 10\n    let g:vrc_cookie_jar = '/path/to/cookie'\n    let g:vrc_follow_redirects = 1\n    let g:vrc_include_response_header = 1\n    let g:vrc_max_time = 60\n    let g:vrc_resolve_to_ipv4 = 1\n    let g:vrc_ssl_secure = 1\n\nUsing cUrl options,\n\n    let g:vrc_curl_opts = {\n      \\ '--connect-timeout' : 10,\n      \\ '-b': '/path/to/cookie',\n      \\ '-c': '/path/to/cookie',\n      \\ '-L': '',\n      \\ '-i': '',\n      \\ '--max-time': 60,\n      \\ '--ipv4': '',\n      \\ '-k': '',\n    \\}\n\n#### 5.2 Global Definitions\n\nThe global section is separated from the rest with two dashes `--` and may\ninclude a default host, optional default cUrl options (buffer scope) and\noptional default headers. These values are always included in each request.\n\nEach request block has to start with either two dashes indicating it uses the\ndefault host from the global section or any host only used by this block. If\na 'local host' is given, it's used instead of the one specified in the global\nsection. Additionally, a request block can specify extra cUrl options and\nheaders. Local headers are merged with and overwrite global headers.\n\n    # Global definitions.\n    // Default host.\n    https://domain[:port]/...\n\n    // Default (buffer scope) cUrl options.\n    -L\n    --connect-timeout 10\n\n    // Default headers.\n    Accept: application/json\n    X-Header: Custom Data\n    --\n\n    # Request block that uses default values from the global section.\n    --\n    GET /some/query\n\n    # Request block that specifies its own host and extra headers.\n    // Local host.\n    http://example.net:9200\n\n    // Local cUrl opts.\n    -k\n    --ipv4\n    // This cUrl option overwrites the one in the global section.\n    --connect-timeout 30\n    -b /path/to/cookie\n    -c /path/to/cookie\n\n    // Extra headers.\n    Xtra-Header: Some Extra.\n    // This header will overwrite the one in the global section.\n    X-Header: New Data\n\n    POST /service\n    var1=value\n\n#### 5.3 Global Variable Declaration\n\nVRC now supports variable declarations in the global scope. These variables\nthen can be used in the query paths, headers, and the body. Notice: values\nare not url-encoded.  Variables can contain static text, or reference an\nenvironment variable:\n\n    # Global scope.\n    http://host\n\n    // Variable declarations (value passed as is).\n    foobar = LoremIpsum\n    city = Some%20City\n    zip = 12345\n    population = 42\n    restpassword = $SECRET_ENV_VAR\n    --\n    # End global scope.\n\n    --\n    GET /city/:city\n\n    --\n    GET /city/:city/zip/:zip\n\n    --\n    custom-header :foobar\n    POST /city/:city\n    { \"population\": :population }\n\n#### 5.4 Line-by-line Request Body\n\nSince version 2.3.0, the request body can be specified on a line-by-line\nbasis. It's useful for name-value pair services. Each line of the request\nbody is passed to cURL using `--data` or `--data-urlencode` depending on\nthe verb.\n\nTo enable,\n\n    let g:vrc_split_request_body = 1\n\nor\n\n    let b:vrc_split_request_body = 1\n\nThen the request body can be specified as\n\n    #\n    # The following params in the request body will be\n    # sent using `--data-urlencode`\n    #\n    http://localhost\n    Content-Type: text/html; charset=UTF-8\n    GET /service\n    var1=value1\n    var2=value2\n\nThis option won't take effect for `GET` request if the option\n`vrc_allow_get_request_body` is set.\n\n#### 5.4 Consecutive Request Verbs\n\nA request block may have consecutive request verbs. The output of each request\nverb is appended to the output view.\n\n    http://localhost:9200\n    PUT /test\n    GET /test\n    DELETE /test\n\n### 6. Configuration\n\nhttps://github.com/diepm/vim-rest-console/blob/master/doc/vim-rest-console.txt\n\n### 7. Tips 'n Tricks\n\n#### 7.1 POST Data in Bulk\n\nSince v3.0, VRC supports POSTing data in bulk using in-line data or an\nexternal data file. It's helpful for such APIs as Elasticsearch's Bulk API.\n\nTo use in-line data, first enable the Elasticsearch support flag.\n\n    let g:vrc_elasticsearch_support = 1\n\nThe request would look like this.\n\n    http://localhost:9200\n    POST /testindex/_bulk\n    { \"index\": { \"_index\": \"test\", \"_type\": \"product\" } }\n    { \"sku\": \"SKU1\", \"name\": \"Product name 1\" }\n    { \"index\": { \"_index\": \"test\", \"_type\": \"product\" } }\n    { \"sku\": \"SKU2\", \"name\": \"Product name 2\" }\n\nUsing external data files doesn't need the support flag.\n\n    http://localhost:9200\n    POST /testindex/_bulk\n    @data.sample.json\n\nYou can also PUT contents of a file using the same syntax. This is\nequivalent to passing --data-binary flag to cURL.\n\n    http://localhost:9200\n    PUT /testindex/_bulk\n    @data.sample.json\n\n#### 7.2 Syntax Highlighting\n\nThough VRC supports output syntax highlighting, it's based on the response\nContent-Type. When Content-Type is not present, the output can still be\nsyntax-highlighted if the appropriate ftplugin is installed. To force the\noutput highlighting based on `filetype`, place this setting in `.vimrc`:\n\n    let g:vrc_output_buffer_name = '__VRC_OUTPUT.\u003cfiletype\u003e'\n\n`filetype` can also be set in the output buffer on an ad hoc basis.\n\n    # vim: set ft=json\n\n### 8. Contributors\n\nThanks to the contributors (in alphabetical order of GitHub account)\n\n    @dan-silva\n    @dflupu\n    @iamFIREcracker\n    @jojoyuji\n    @korin\n    @minhajuddin\n    @mjakl\n    @nathanaelkane\n    @p1otr\n    @rawaludin\n    @rlisowski\n    @sethtrain\n    @shanesmith\n    @tdroxler\n    @tonyskn\n    @torbjornvatn\n\n### 9. License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiepm%2Fvim-rest-console","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiepm%2Fvim-rest-console","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiepm%2Fvim-rest-console/lists"}