rest-nvim / tree-sitter-http

HTTP grammar for tree-sitter
MIT License
34 stars 17 forks source link

Feature request: multiline variables #20

Closed mawkler closed 1 month ago

mawkler commented 1 year ago

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'
NTBBloodbath commented 6 months ago

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

boltlessengineer commented 1 month ago

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