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

How to make use of variable to remember the response and use it in subsequence command? #10

Open
geohuz opened this issue Jan 3, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@geohuz
Copy link

geohuz commented Jan 3, 2023

For application using JWT token this is the typical use case, like this in my current curl script:

TOKEN=$(curl   -d '{"email": "vicky@gmail.com", "pass": "hello"}' -H 'Content-Type: application/json'  http://localhost:3210/rpc/login | jq -r '.token')

curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" http://localhost:3210/user_articles?select=title

The first line gets the token from the response and then use the token to GET the result from the second line request.

@shrsv
Copy link
Contributor

shrsv commented Jan 3, 2023

A solution to this chaining problem is still in the works; will update here once it's ready.

@shrsv shrsv added the enhancement New feature or request label Jan 3, 2023
@shrsv
Copy link
Contributor

shrsv commented Jan 14, 2023

Quick update: Started an experimental branch goja, to try to embed a JS processor to enable chaining requests.

Also delegating to a scripting lang, is in line with design philosophy of "delegate to mature tools". By the way, this is pure JS - so we won't allow importing arbitrary npm modules.

Why JS:

  1. Most people working with APIs probably already know JS
  2. Easy to support XPath/JSONPath or even JQ clones right into JS
  3. Even if you don't know any of (2), simple JS object notation + good old loops will take you far
  4. Native support for JSON (and dom manipulation is common too, for xml type responses)
  5. Good amount of power for implementation effort exerted

For simple use case mentioned above in the thread, one barely has to understand JS to process some JSON and store a variable

Some example files with both Requester + Processor (JS) blocks:

Trivial example:

url = "https://google.com"
---
GET
https://${url}

Advanced:

# stage 1

POST
${LOCAL_COORD}/api/login/

{
    "username": "admin",
    "password": "Password@123"
}

---

// filtering, store in var; keyword "let" optional
let TOKEN = result["Token"] 

---

# stage 2
GET
${LOCAL_COORD}/listorgstyle

Authorization: 'Token ${TOKEN}’'

{}

Any early thoughts/comments/suggestions welcome.

PS: Implementation still in progress

@shrsv
Copy link
Contributor

shrsv commented Jan 25, 2023

@geohuz - latest release allows chaining requests through Javascript blocks. Please try whenever possible and let me know if any issues.

LinceMathew pushed a commit that referenced this issue Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants