tree-sitter-http
tree-sitter-http copied to clipboard
Feature request: multiline variables
It would be neat if I could divide a JSON variable into multiple lines.
The following request
@value = {
"foo": 1,
"bar": 2
}
POST http://localhost
{{value}}
yields the following curl request
curl -sSL --compressed -X 'POST' --data-raw '{' 'http://localhost'
As you can see, only the first line ({) of the object in @variable gets included in the request
Expected result:
curl -sSL --compressed -X 'POST' --data-raw '{ "foo": 1, "bar": 2 }' 'http://localhost'
Note: transferred from rest.nvim repository as this has something to do with the parser grammar.
variables in http syntax can be only strings but nothing else, just like environment variables.
If you want to define variable in multi-line form, you can use pre-request script to construct the variable:
@foo=123
# @lang lua
{%
local myobj = {
foo = tonumber(request.variables.get(“foo”)),
bar = “bar”,
}
request.variables.set(“body”, vim.json.encode(myobj))
%}
POST http://localhost
{{body}}