rest-nvim / rest.nvim

A fast Neovim http client written in Lua
GNU General Public License v3.0
1.35k stars 117 forks source link

[Bug] Can't recognize the variable in header #378

Open Alienover opened 1 month ago

Alienover commented 1 month ago
image

The {{TOKEN}} in this case, is parsed as value, instead of variable.

The header should be parsed to

  header
    name: name
    value: value
    value: value
    value: variable
      name: identifier
malisoft commented 1 month ago

Same problem, in my case, i tried image in older versions works, but i still i love this package, only is solve this little problem

malisoft commented 1 month ago

Same problem, in my case, i tried image in older versions works, but i still i love this package, only is solve this little problem

i find a solution, the problem iss because by some reason does not work when is together "Bearer {{TOKEN}}" i created another env file called ".env.http" selecting this env file using the Telescope rest env selector and storing in this env file:

TOKEN=Bearer ey.......

note that i am using a variable with a content without spaces between the texts(the problem was laravels does not support spaces un the env variables as well)

Finally this works:

GET {{APP_URL}}/api/1.0/apps?per_page=15
Authorization: {{TOKEN}}
Content-Type:application/json
Alienover commented 1 month ago

@malisoft that's the solution I am using.... have to replace the whole Authorization value.

NTBBloodbath commented 1 month ago

Hi, sorry for the delay. Life has been kinda busy and I'm still during exams weeks :/

I'm going to move this issue to the tree-sitter-http repository, as it seems to be a problem with the parser and not with rest.nvim itself and fix it as soon as I have some spare time to work on it.

Alienover commented 1 month ago

https://github.com/rest-nvim/tree-sitter-http/issues/29 I created this issue in tree-sitter-http before. No one replied, so I duplicated it here for visibility.

javoscript commented 4 weeks ago

I was having issues with setting the Authentication: Bearer XXXXX header, and it ended up being a problem when three conditions happen at the same time:

Whenever all happen, setting the header like this won't work:

GET /api/test
host: {{API_BASE_URL}}
Accept: application/json
Authorization: Bearer {{BEARER_TOKEN}}

The value received by the server is just Authorization: Bearer.

BUT, if the env variable already contains the whole value (with the Bearer part), then it works.

Here a snippet of how I'm setting the complete Authorization header value:

POST /api/auth
host: {{API_BASE_URL}}
Content-Type: application/json

{
   "email": "email@example.com",
   "password": "secret"
}

--{%

local body = context.json_decode(context.result.body)
context.set_env("BEARER_TOKEN", "Bearer " .. body.token)

--%}