RESTer
RESTer copied to clipboard
Add value from the response to the environment
I'm testing a system that uses an authentication based on a service. This login service returnes something like a session id as part of the response (JSON). This session id I have to send in subsequent requests as header value. Right now I have to add it manually to the environment after each login. Therefore I would like to have a simple way to add a value of the response to a given key in the environment.
Hi @gadton. This is a great idea and it is definitely on my todo list.
I struggeling to come up with a good solution for it, which is why I postponed this idea. Lots of questions come to my mind:
- Where do wou configure this?
- Request: select an environment where to inject certain values of the response.
- Environment: pull something out of recently made requests/responses.
- How do you specify what part of the response you want to have?
- You might want to pull values out of the response headers or body.
- The body could be JSON, but also XML or something else.
- A JSON path might work, e.g.
body.data.0.session
orheaders.my-custom-data
for a response like this:{ "headers": { "content-type": "application/json", "my-custom-data": "bananas" }, "body": { "data": [ { "session": "secret123!" } ] } }
- This might be hard to understand, though. How should the UI for this look like?
Still, I do really like the idea. Apart from your login requirement, it could also make it possible to easily do a chain of dependend requests.
Hi @frigus02, here are some ideas:
- a manual solution could be to just add a context menu to the response view providing an item "Set selection to environment variable" with a sub item for each environment variable
- automated solution
- I think the request is the right place
- this would lead to something like response-triggers; each trigger should have
- a check if it should be executed (e.g. status == 200)
- an action
- as you proposed +1
- for the experienced: a few lines of JavaScript with access to request, response and env
Hope that helps
Thanks a lot for your ideas. I like the response-triggers.
A few lines of JavaScript would be amazing. I'm not sure which security issues this might bring. How can you savely evaluate JavaScript in a browser extension, which has elevated permissions? I'm sure there are solutions for, though.
workaround after receive response you can copy session id to variable {SESSION_ID} and it will be used in all requests