Home

Awesome

<div align="center">

resty.nvim

Build Status License Stars

A fast and easy-to-use HTTP-Rest-Client plugin for Neovim, completely written in LUA.

FeaturesInstallSyntaxExamples

image

</div>

Features

These are the features that contribute to this goal:

Install

Supported Neovim versions:

Dependencies

Syntax

Syntax highlight

There are two supported filetypes:

Syntax in action

# variable for the hostname
@hostname = httpbin.org          # variable with value
@hostname = {{$HOSTNAME}}        # from environment variable (start symbol: '$')
@hostname = {{>  ./myscript.sh}} # from script (start symbol: '>')
@hostname = {{>> ./myscript.sh}} # from script (start symbol: '>>'), the result will be cached
@hostname = {{:hostname}}        # with input prompt (start symbol: ':')

# prefix: @cfg. means configuration from curl and/or resty
@cfg.timeout = 1000              # curl configuration for timeout 
@cfg.check_json_body = true      # resty configuration to validate the json body

###  #my favorite
GET https://{{hostname}}/get?id=7
# you can click (set the cursor) on {{hostname}} and get displayed the current value
accept: application/json  
# id = 7 this equivalent to ?id=7

### 
# local variable overwrites global variable
@hostname = jsonplaceholder.typicode.com

POST https://{{hostname}}/comments
accept: application/json  

{ "comment": "my comment" }

In LUA scripts you can use an ctx table, which has access to the following properties and methods:

local ctx = {
    -- result of the current request
    -- body = '{}', status = 200, headers = {}, exit = 0, global_variables = {}
    result = ...,
    -- set global variables with key and value
    set = function(key, value) end,
    -- parse the JSON body
    json_body = function() end,
    -- jq to the body
    jq_body = function(filter) end,
}

Commands

User commandDescription
:Resty runrun request under the cursor OR <br>in visual mode run the marked request rows
:Resty run [request definition]run request which is given by input, rows are seperated by \n<br> (you can simulate \n with <C-v><CR> in command mode)
:Resty lastrun last successfully executed request
:Resty favoriteshow a telescope view with all as favorite marked requests
:Resty favorite [my favorite]run marked request my favorite, independend, where the cursor is or in which buffer

Examples for using a command with a keymap configuration:

vim.keymap.set({"n","v"},"<leader>rr", ":Resty run<CR>",{desc="[R]esty [R]un request under the cursor"})
vim.keymap.set({"n","v"},"<leader>rv", ":Resty favorite<CR>",{desc="[R]esty [V]iew favorites"})

Response|Result view

There are four views for the result (the rest-call-response)

viewshort cutdescription
bodybresponse body
headershresponse headers
infoishows information from the call and response
??shows help information for keybindings

Short cuts for the view: body

jq must be installed!

short cutdescription
pjson pretty print
qjq query
rreset to the origininal json

Hint: with cc can the curl call canceled.

Examples

Give a star for this great project ;-)

PUT https://api.github.com/user/starred/lima1909/resty.nvim
Authorization: Bearer {{my-token}}
Accept: application/vnd.github+json

Login with saving the result token

POST https://reqres.in/api/login
accept: application/json  
Content-type: application/json ; charset=UTF-8

{
    "email": "eve.holt@reqres.in",
    "password": "cityslicka"
}

# response: { "token": "QpwL5tke4Pnpja7X4" }
# save the token into the variable: {{login.token}}

--{%
  local body = ctx.json_body()
  ctx.set("login.token", body.token)
--%}

Call with query parameter

GET https://reqres.in/api/users
delay = 1

### both are the same
GET https://reqres.in/api/users?delay=1 

Post with body

POST https://api.restful-api.dev/objects
accept: application/json  
Content-type: application/json; charset=UTF-8

{
   "name": "MY Apple MacBook Pro 16",
   "data": {
      "year": 2019,
      "price": 1849.99,
      "CPU model": "Intel Core i9",
      "Hard disk size": "1 TB"
   }
}