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
cargo install rested
or from npmjs.com
npm install -g rstd
Language/Interpreter for easily defining and running requests to an http server.
Usage: rstd [OPTIONS] <COMMAND>
Commands:
run Run a script written in the language
scratch Open your default editor to start editing a temporary file
snap Generate a static snapshot of the requests with all dynamic values evaluated
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
config Configure, or view current configurations
help Print this message or the help of the given subcommand(s)
Options:
-l, --level <LEVEL> Set log level, one of trace, debug, info, warn, error [default: info]
-h, --help Print help
-V, --version Print version
Write a script, for example
// assuming file name requests.rd
@log
get https://jsonplaceholder.typicode.com/todos/1
Run it with the CLI.
rstd run requests.rd
set BASE_URL "http://localhost:8080/api/v2"
setting BASE_URL like so, allows you to be able to make request to just pathnames
// This will make a request to "http://localhost:8080/api/v2/potatoes"
get /potatoes
let token = "<token>"
// template string literals
let bearer_token = `Bearer ${token}`
post /potatoes {
header "Authorization" "Bearer token"
// json expressions
body json({
neet: 1337,
stuff: [1, true, "three"]
})
}
set BASE_URL env("base-url")
post /tomatoes {
header "Authorization" env("auth-token")
body env("data")
}
rstd env set <name> <value>
It's also possible to namespace the variables.
rstd env set <name> <value> -n <namespace>
Operate on the environment variables available in the runtime
Usage: rstd env [OPTIONS] <COMMAND>
Commands:
show View environment variables available in the runtime
edit Edit environment variables in your default editor
set Set environment variables available in the runtime
ns Operate on the variables namespaces available in the runtime
help Print this message or the help of the given subcommand(s)
Options:
-l, --level <LEVEL> Set log level, one of trace, debug, info, warn, error [default: info]
-h, --help Print help
post /tomatoes {
body read("data.json")
}
// prints response body to stdout
@log
get /yams
// prints response body to a file
@log("output/yams.json")
get /yams
There are more, but I'm kind of ashamed of these attributes, so let's stop.
I doubt this language server will ever land into neovim/nvim-lspconfig
, so here's an example
of my lsp config setup.
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
nvim_lsp.rstdls.setup({
on_attach = on_attach, --[[your on_attach function goes here]]
single_file_support = true,
root_dir = nvim_lsp.util.root_pattern(".env.rd.json"),
capabilities = require('cmp_nvim_lsp')
.default_capabilities(vim.lsp.protocol.make_client_capabilities())
})