Language/Interpreter for easily defining and running requests to an http server.
To easily test apis during development, and the Postman experience is slow. As someone who edits text files professionally, it seems natural to have a DSL for this usecase as well. It's a much better workflow to use curl commands in shell scripts than clicking around a GUI. Many developers have great success with that strategy, and it's powerful because linux (piping files) is powerful. But it could be simpler to still to have a DSL. Hence this experiment.
From crates.io
sh
cargo install rested
or from npmjs.com
sh
npm install -g rstd
``` The CLI runtime for Rested, the language/interpreter for easily defining and running requests to an http server
Usage: rstd [COMMAND]
Commands: run Run a script written in the language env Operate on the environment variables available in the runtime completion Generate a completions file for a specified shell lsp Start the rested language server help Print this message or the help of the given subcommand(s)
Options: -h, --help Print help -V, --version Print version ```
Write a script, for example
rd
// assuming file name requests.rd
@log
get https://jsonplaceholder.typicode.com/todos/1
Run it with the CLI.
sh
rstd run requests.rd
rd
set BASE_URL "http://localhost:8080/api/v2"
setting BASE_URL like so, allows you to be able to request to pathnames
rd
get /potatoes
rd
let variable = "Bearer <token>"
```rd post /potatoes { header "Authorization" "Bearer token"
// template string literals
body {"neet": 1337}
// or json-like expressions body { neet: 1337 } } ```
```rd set BASE_URL env("base-url")
post /tomatoes { header "Authorization" env("auth-token") body env("data") } ```
sh
rstd env set <name> <value>
It's also possible to namespace the variables.
sh
rstd env set <name> <value> -n <namespace>
rd
post /tomatoes {
body read("data.json")
}
rd
@log("output/yams.json")
get /yams
I doubt this language server will ever land into neovim/nvim-lspconfig
, so here's an example
of my lsp config setup.
```lua local nvim_lsp = require("lspconfig");
local configs = require 'lspconfig.configs'
if not configs.rstdls then configs.rstdls = { default_config = { cmd = { "rstd", "lsp" }, filetypes = { "rd" }, }, } end
nvimlsp.rstdls.setup({ onattach = onattach, --[[your onattach function goes here]] singlefilesupport = true, capabilities = require('cmpnvimlsp') .defaultcapabilities(vim.lsp.protocol.makeclient_capabilities()) }) ```