rest-nvim / rest.nvim

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

Unable to read default env variables #308

Closed radvil closed 6 months ago

radvil commented 6 months ago
[rest.nvim] WARN: The variable 'BASE_URL_V3' was not found in the document or in the environment. Returning the string as received ...

Here is my ENV config located in the same directory as the *.http file that ran this command

BASE_URL_V3=https://api.themoviedb.org/3
READ_ACCESS_TOKEN=my-access-token-xxx

And following is the request

GET {{BASE_URL_V3}}/movie/popular?language=en-US&page=1
Content-Type: application/json
Authorization: Bearer {{READ_ACCESS_TOKEN}}
NTBBloodbath commented 6 months ago

Oh woops, I think it is a problem with the implementation. Currently it works with a path relative to where Neovim was opened, Does it work for you if your current working directory is where your files are?

I didn't notice that error because I have an autocommand that modifies my cwd in Neovim, thanks for reporting it 😅

radvil commented 6 months ago

Oh woops, I think it is a problem with the implementation. Currently it works with a path relative to where Neovim was opened, Does it work for you if your current working directory is where your files are?

I didn't notice that error because I have an autocommand that modifies my cwd in Neovim, thanks for reporting it 😅

Humm, I try to cd into the file's cwd and opened the http file and it's still happen, the output vim.loop.cwd() of shows that I am at the file's directory already. Did I do it wrong ?

NTBBloodbath commented 6 months ago

That's odd. Does it happen if you try to manually load the environment variables file with :lua require("rest-nvim.parser.env_vars").read_file(false)? If the function ran without errors you can check if the variable is loaded by using :=vim.env.BASE_URL_V3 and it shouldn't return nil

radvil commented 6 months ago

That's odd. Does it happen if you try to manually load the environment variables file with :lua require("rest-nvim.parser.env_vars").read_file(false)? If the function ran without errors you can check if the variable is loaded by using :=vim.env.BASE_URL_V3 and it shouldn't return nil

Oh yeah, running the command manually inside the http file dir seems to works just fine, but seems like it doesn't read my Authorization header (still with the same setup as above). Following is the output when I go the next pane (Headers)

Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Date: Tue, 19 Mar 2024 15:59:12 GMT
Server: openresty
Cache-Control: public, max-age=300
X-Cache: Error from cloudfront
Via: 1.1 7aabf4a3a1d35735380ea2b24910ae5e.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: CGK51-P3
Alt-Svc: h3=":443"; ma=86400
X-Amz-Cf-Id: GQ5f0rbNyYLuKaJEXKm1L9gwjrQ6JTWtIn5jrKqHC3_oTPmPdtFc3Q==
Vary: Origin

And following is the response I got by running the same file:

GET https://api.themoviedb.org/3/movie/popular?language=en-US&page=1
HTTP/1.1 401 Unauthorized

#+RES
{
  "status_code": 7,
  "status_message": "Invalid API key: You must be granted a valid key.",
  "success": false
}
#+END

The Authorization Header seems missing, IDK whether it was me who did it wrong ??

NTBBloodbath commented 6 months ago

Oh yeah, running the command manually inside the http file dir seems to works just fine

Oh yes, I just found a small bug in the last refactor I did regarding the handling of .env, I'm pushing it now :)

The Authorization Header seems missing, IDK whether it was me who did it wrong ??

I think in the rewrite I forgot to add support for authentication (which didn't exist in v1 either, perhaps that's why it didn't was in my list), but I'm already reading the lua-curl code to add support for it, it shouldn't take me long.

Edit: could you please open a separate issue for the Authentication issues? That way it would be more organized and I can keep track of everything 🙂

radvil commented 6 months ago

yeah sure, this safe to close rn.

mrlectus commented 4 months ago

Mine only worked when i put quotes around it, Why?