Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to write variables to .env file #349

Open
kalidyasin opened this issue Apr 4, 2024 · 7 comments
Open

Unable to write variables to .env file #349

kalidyasin opened this issue Apr 4, 2024 · 7 comments

Comments

@kalidyasin
Copy link

kalidyasin commented Apr 4, 2024

it runs :REST run successfully but it is not writing the response variable in .env file

POST {{URL}}/api/signin
Content-Type: application/json

{
    "email": "{{USERNAME}}",
    "password": "{{PASSWORD}}"
}
--{%

local body = context.json_decode(context.result.body)

-- These environment variables are stored in 'vim.env'
context.set_env("TOKEN", body._token)
context.set_env("studentid", body.student_id)
context.set_env("certificate", body.certificate_type)
context.set_env("userid", body.user)

--%}

.env file

URL=http://127.0.0.1
USERNAME=test@test.com
PASSWORD=password

http file
silicon_20240406_184843
env file
silicon_20240406_185024

@harrylowkey
Copy link

I have the same issue like you, have you fixed it?

@kalidyasin
Copy link
Author

no it is not fixed

@filipiz
Copy link

filipiz commented May 15, 2024

it is described in the test example:

-- These environment variables are stored in 'vim.env'

it will not save the variable to the file.
it will set the variable to vim.env so you can use it.

if you run :lua print(vim.env.userid) after executing the request, it should print whatever comes in the response.

@NTBBloodbath
Copy link
Member

Storing variables in an env file was kinda problematic before due to the implementation of it. I'll give it a new life once I get some vacations from exams in the uni and hopefully that one will be good enough :)

@kalidyasin
Copy link
Author

it is described in the test example:

-- These environment variables are stored in 'vim.env'

it will not save the variable to the file. it will set the variable to vim.env so you can use it.

if you run :lua print(vim.env.userid) after executing the request, it should print whatever comes in the response.

yes but it is not working if the value is too long like token

@filipiz
Copy link

filipiz commented May 24, 2024

It's working for me. I'm storing JWT tokens in my cases, they are quite long.
If there is any limitation on nvim.env vars it may be detailed on nvim help files, I guess.

@filipiz
Copy link

filipiz commented May 24, 2024

I really enjoyed the current solution, @NTBBloodbath.
Although I miss the possibility to run a script before the curl request is executed.

I have a use case where I have to generate a "signature" header, that is a hash based on request params and body.

I have hacked the previous version of the plugin to make something similar work to me.
On that hack, I set a couple headers like this:

X-Rest-Nvim-Pre-Script: signature.lua
X-Rest-Nvim-Post-Script: set_user.lua

and these scripts were executed before and after the request.

Never had the chance to polish and open a pull request.
And on this version you have already solved half of the problem.

I'll try to make a pull request as soon as I can find some time to make something useful.

Good luck on your exams!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants