-
Notifications
You must be signed in to change notification settings - Fork 6
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
Feature: run a Lua script after the request ends #56
Comments
@name-jerry Are you thinking this is something that would be added in the config, and put in an environment variable? |
I have seen how to configure environment variables using config. I want to add a default variable such as response; It is used to store the returned results and then run lua to retrieve the variables for later requests |
@oysandvik94 I also think this would be a nice to have feature.
I think, the easiest method would be to have the ability to define a script per collection.
And if the user wants the script to be only executed on a specific curl request, they could add specific conditions inside the script like this if req.path == "/api/v1/login" and req.method == "POST" then
vim.fn.setenv("TOKEN", res.json.token)
return
end Now that I'm thinking about it, this method could solve #29 and #12 vim.fn.setenv("HOST", "http://localhost:8080")
vim.fn.setenv("TOKEN", "....") |
It's a great idea to reuse code, but my idea is more like resty's implementation;or something like the following:
This way I can quickly switch accounts as needed. |
I see what you guys mean! But it shouldnt be hard to just grab a field from the response json using lua's json thing. Just a wild idea: const tokenResponse = curl http://url/api/v1/login
-H 'Content-Type: application/json'
-d
{
username: "admin",
password:"xx"
}
curl http://url/api/v1/resource-name
-H "Authorization: Bearer $tokenRespones.token"
-H 'Content-Type: application/json'
-d
{
id:xx
} |
It's a great idea to let curl just be curl;I'm pretty sure that's what I want |
Yup, I agree as well |
Sweet, I'll try this weekend. With this I can eventually formalize the syntax and create an LSP too maybe for autocompletion and stuff. |
Just an update on this: Sorry this got delayed. I had some problems with the test setup, so I decided to switch to mini.test and rewrite all the tests. |
Thank you for your work on the project. I'm looking forward to seeing the results. |
Since I went MIA for so long last time I thought I'd give a little update: I'm very close now, so hopefully I'll be finished early next week. I'm in the process of starting a new job, so I've been a bit busy lately, |
For example, save the token from the response result into a variable for future use.
The text was updated successfully, but these errors were encountered: