-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: make BrunoResponse
callable to access body data using expressions fixes (#481)
#3710
base: main
Are you sure you want to change the base?
Conversation
@@ -36,6 +44,10 @@ class BrunoResponse { | |||
this.body = data; | |||
this.res.data = data; | |||
} | |||
|
|||
call(expr, ...fns) { | |||
return get(this.res.data, expr, ...fns); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't satisfy the full feature. lodash.get does not support array filtering.
Check out the examples given in the docs. The solution should satisfy the example inputs and outputs as written. |
@Kenttleton Thanks for your valuable input. I will update this PR |
I recommend using the JSONPath library instead of lodash as it gets you most of the way there. This lib is also used in Bruno to filter responses and has a similar syntax as the docs. Don't forget to add an optional callback to the signature for further refinements and please provide test cases for your implementation. |
fixes: #481
Description
This PR introduces the ability to use the
res
object as a callable function to access body data directly. For example:This functionality simplifies post-response scripting. Currently, developers has a workaround:
With this PR, the
res
object can now be used both as an object and as a function, providing a more convenient way to scripts.Contribution Checklist: