tree-sitter-http icon indicating copy to clipboard operation
tree-sitter-http copied to clipboard

Feature request: multiline variables

Open mawkler opened this issue 2 years ago • 1 comments

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'

mawkler avatar Jan 18 '23 16:01 mawkler

Note: transferred from rest.nvim repository as this has something to do with the parser grammar.

NTBBloodbath avatar Mar 16 '24 20:03 NTBBloodbath

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}}

boltlessengineer avatar Aug 30 '24 10:08 boltlessengineer