[PR #231] [MERGED] Feature/pre request script #2502

Closed
opened 2026-03-17 00:12:07 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/231
Author: @nickpalenchar
Created: 10/30/2019
Status: Merged
Merged: 10/30/2019
Merged by: @liyasthomas

Base: masterHead: feature/pre-request-script


📝 Commits (4)

  • 668f99c pre-request script working
  • 36fb517 update search tearm and parse more data
  • 1bf17d5 Merge branch 'master' into feature/pre-request-script
  • ad1c745 Added β symbol to , few minor UI updates before production deployment

📊 Changes

4 files changed (+83 additions, -7 deletions)

View changed files

📝 components/history.vue (+7 -0)
functions/preRequest.js (+17 -0)
functions/templating.js (+7 -0)
📝 pages/index.vue (+52 -7)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/231 **Author:** [@nickpalenchar](https://github.com/nickpalenchar) **Created:** 10/30/2019 **Status:** ✅ Merged **Merged:** 10/30/2019 **Merged by:** [@liyasthomas](https://github.com/liyasthomas) **Base:** `master` ← **Head:** `feature/pre-request-script` --- ### 📝 Commits (4) - [`668f99c`](https://github.com/hoppscotch/hoppscotch/commit/668f99c37f04e18520882fc73d10b05d8a0fe6e7) pre-request script working - [`36fb517`](https://github.com/hoppscotch/hoppscotch/commit/36fb51705b469aa5527e5f4b28b86c17d408a04c) update search tearm and parse more data - [`1bf17d5`](https://github.com/hoppscotch/hoppscotch/commit/1bf17d5514715e22c18faac81c0ec50218fbc6ad) Merge branch 'master' into feature/pre-request-script - [`ad1c745`](https://github.com/hoppscotch/hoppscotch/commit/ad1c7450ab17908a8499093b28072b0784e70811) :zap: Added β symbol to , few minor UI updates before production deployment ### 📊 Changes **4 files changed** (+83 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `components/history.vue` (+7 -0) ➕ `functions/preRequest.js` (+17 -0) ➕ `functions/templating.js` (+7 -0) 📝 `pages/index.vue` (+52 -7) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 00:12:07 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#2502
No description provided.