Goes well with rest.nvim
Example:
locals {
url = "http://localhost:8080"
name = "world"
}
// test
request "hell_yeah" {
url = "${locals.url}/get"
method = "GET"
headers = [
"X-TEST: you:😄",
]
}
request "httpbin post" {
method = "POST"
url = "https://httpbin.org/post"
headers = [ "Content-Type: application/json" ]
body = {
hello: "${locals.name}"
}
# has lua interpreter to post process check docs for more
post_hook = <<LUA
local body = json.decode(rest.res.body)
local ret = json.decode(body.data) -- what_we_sent_to_httpbin
print(inspect(ret)) -- { hello = "world" }
return ret.hello -- cli prints -> world
LUA
}
Server/Client:
Testing:
rest -h
=== Rest Easy ===
CLI:
--no-color, -nc:
No colors
Server:
--addr, -a:
Address to listen on
--serve, -s:
Run a server
--dir, -d:
Directory to serve
--origins, -o:
Add Access-Control-Allow-Origin header value
ex: -o * or -o 'http://localhost:8080 http://localhost:3000'
--tls, -t:
TLS path name to be used for tls key/cert (defaults to no TLS)
ex: '-t ./keys/site.com' where the files ./keys/site.com.{key,crt} exist
--quiet, -q:
Don't log server requests
Client:
--file, -f:
File to run
--block, -b:
Request block to run, 0-indexed
--label, -l:
Request label to run
--socket, -S:
Run the socket block (ignores requests)
if set like "--socket/-S run", rest will run socket.run.order and exit
--export, -e:
Export file to specified language
--client, -c:
Export full client instead of individual requests
--verbose, -v:
More client logging
- request.copy_from = "label"
- decode locals in blocks so they can be used as they are parsed
- proxy requests to add headers or basic auth