-
-
Notifications
You must be signed in to change notification settings - Fork 150
Open
Description
Problem Description
I'm trying to access environment variables defined in my .env file within post-request Lua scripts, but os.getenv() returns nil even though the environment file is properly loaded and selected.
Steps to Reproduce
-
Created a
.envfile with the following content:PLATFORM=Prod -
Used
:Rest env selectcommand to select the env file -
Verified the file is loaded with
:Rest env show(shows correct file path) -
Created an HTTP request with a post-script:
POST {{baseurl}}/reset # @lang=lua > {% print(os.getenv("PLATFORM")) %}
Expected Behavior
The post-script should print Prod (the value of the PLATFORM environment variable).
Actual Behavior
The post-script prints nil.
Environment
- rest.nvim version commit as per Lazy.nvim:
"rest.nvim": { "branch": "main", "commit": "de9726ab956e30202aafbcdea83c1d6bffe54227" }
- Neovim version:
NVIM v0.11.1
Build type: Release
LuaJIT 2.1.1741730670
Run "nvim -V1 -v" for more info- OS:
PRETTY_NAME="Ubuntu 24.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.2 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logoQuestions
- Is
os.getenv()the correct way to access environment variables from the.envfile in post-scripts? - Are environment variables from the
.envfile supposed to be available in the Lua execution context? - Is there a different API or method to access these variables in post-scripts?
- How can I debug what variables are available in the post-script execution context?
Additional Context
- The
{{baseurl}}variable substitution works correctly in the request itself - The
:Rest env showcommand confirms the environment file is loaded
Any guidance on the proper way to access environment variables in post-request scripts would be greatly appreciated!
Originally posted by @maniac-en in #549
Metadata
Metadata
Assignees
Labels
No labels