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

Feature/pre request script #231

Merged
merged 4 commits into from
Oct 30, 2019
Merged

Feature/pre request script #231

merged 4 commits into from
Oct 30, 2019

Conversation

aeeed99
Copy link
Contributor

@aeeed99 aeeed99 commented Oct 30, 2019

fixes #218

scrapped the old branch feature/dynamic-headers after merge woes (will delete soon).

Lots more to think about, but I feel it satisfies mvp (and would love to get this in master so I can take a break from keeping it up-to-date manually 😅)

Request section has a code button. When clicked, it enables pre-request scripts. A pre-request script section appears above where javascript can be entered.

pre-request script has access to a postwoman api object (pw) that can be interacted with. Right now the only thing to do is pw.environment.set("key", "value") to set a variable that can be used in areas of the request. Note this is native javascript, so any js method can be used. Final values are all treated as strings.

Test by setting something in the pre-request script pw.environment.set("route", "/api/users"); and replacing parts of the request within double angle brackets (path = <<route>>). Response should function the same as if the final value was statically typed.

Additionally, requests made this way end up in history with the same code icon. Hovering over it informs the user that this entry in the history used pre-request scripts. Due to it's highly dynamic potential, you could say that note serves as a warning!

tangentially -- @NBTX can you make the request-chaining into its own issue? I realized it's quite separate from this one so it would be good to address that after this.

@ghost
Copy link

ghost commented Oct 30, 2019

DeepCode Report (#ad1c74)

DeepCode analyzed this pull request.
There are no new issues.

@TravisBuddy
Copy link

Hey @nickpalenchar,
Your changes look good to me!

View build log

TravisBuddy Request Identifier: 44aad4c0-fabd-11e9-94bd-fbbf6873bcfd

@liyasthomas liyasthomas added this to the v1.0 Stable release milestone Oct 30, 2019
@liyasthomas liyasthomas added core Changes regarding core concepts feature New feature or request need testing Needs to be tested before merging onto production labels Oct 30, 2019
@liyasthomas
Copy link
Member

Works good!
I like the indicator in the history section 👍

#todo - after merging to master, I want this to be in production ASAP for more beta testing

  • Toggling pre-script section off will remove already binded properties.
  • useHistory() on history entries with pre-scripts will retain those pre-scripts. We prolly need to store pre-scripts too to history.

Copy link
Member

@liyasthomas liyasthomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@aeeed99
Copy link
Contributor Author

aeeed99 commented Oct 30, 2019

Agreed on the post-merge todos! Additionally, we could also indicate this feature is not fully stable as-is. Something as simple as changing the header to Pre-Request Script (experimental) should be all that’s needed to sufficiently warn users.

@TravisBuddy
Copy link

Hey @nickpalenchar,
Your changes look good to me!

View build log

TravisBuddy Request Identifier: 2c05fc60-fac2-11e9-94bd-fbbf6873bcfd

@liyasthomas liyasthomas merged commit e61ec3e into master Oct 30, 2019
@liyasthomas liyasthomas deleted the feature/pre-request-script branch January 24, 2020 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Changes regarding core concepts feature New feature or request need testing Needs to be tested before merging onto production
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement pre-request and post-request scripts (and request chaining)
3 participants