Skip to content

Commit 2f2de86

Browse files
Pre and Post Script plugin documentation (#36)
Pre and Post script
1 parent 7961ffe commit 2f2de86

47 files changed

Lines changed: 513 additions & 18 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
id: post-script
3+
title: Post Script
4+
sidebar_label: Post Script Blocks
5+
---
6+
7+
# <div style={{display:"flex",alignItems:"center"}}> Post Script <small style={{alignSelf:"start",fontSize:"12px",marginLeft:"10px",padding:"5px",background:"#8a5cf67d",display:"flex",alignItems:"cetner",gap:"5px",borderRadius:"10px"}}><img src="/img/flask-conical.svg" width="14" /> Beta only</small></div>
8+
9+
> **Note:** This feature is currently in **Beta**.
10+
11+
The **Post Script** block lets you run custom logic **after a response is received**.
12+
13+
It executes locally inside Voiden in an isolated environment. Use it to validate responses, extract values, store runtime variables, or write logs.
14+
15+
Voiden supports **JavaScript** and **Python**.
16+
17+
For a full reference of what you can do inside a script, see the [Voiden Script Plugin](/docs/plugins/core-plugins/pre-post%20script/overview).
18+
19+
---
20+
21+
## How to Insert
22+
23+
1. In your Voiden file, type `/post_script` and press **Enter**.
24+
25+
![post-script](/img/voiden-blocks/post-scripts.png)
26+
27+
2. Add your script logic inside the block.
28+
29+
![post-done](/img/voiden-blocks/post-done.png)
30+
31+
3. Run the request with **Cmd + Enter** (Mac) or **Ctrl + Enter** (Windows/Linux).
32+
33+
![post-script-done](/img/voiden-blocks/post-script-done.png)
34+
35+
4. View response and assertions in the **Response panel** and logs in the **Script Logs**.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
id: pre-script
3+
title: Pre Script
4+
sidebar_label: Pre Script Blocks
5+
---
6+
7+
# <div style={{display:"flex",alignItems:"center"}}> Pre Script <small style={{alignSelf:"start",fontSize:"12px",marginLeft:"10px",padding:"5px",background:"#8a5cf67d",display:"flex",alignItems:"cetner",gap:"5px",borderRadius:"10px"}}><img src="/img/flask-conical.svg" width="14" /> Beta only</small></div>
8+
9+
> **Note:** This feature is currently in **Beta**.
10+
11+
The **Pre Script** block lets you run custom logic **before a request is sent**.
12+
13+
It executes locally inside Voiden — not on the API endpoint — in an isolated environment. Use it to dynamically prepare the request: generate tokens, update headers, set variables, or add conditional logic.
14+
15+
Voiden supports **JavaScript** and **Python**.
16+
17+
For a full reference of what you can do inside a script, see the [Voiden Script Plugin](/docs/plugins/core-plugins/pre-post%20script/overview).
18+
19+
---
20+
21+
## How to Insert
22+
23+
1. In your Voiden file, type `/pre_script` and press **Enter**.
24+
25+
![pre-script](/img/voiden-blocks/pre-script.png)
26+
27+
2. Add your script logic inside the block.
28+
29+
![pre-done](/img/voiden-blocks/pre-done.png)
30+
31+
3. Run the request with **Cmd + Enter** (Mac) or **Ctrl + Enter** (Windows/Linux).
32+
33+
![pre-script-done](/img/voiden-blocks/pre-script-done.png)
34+
35+
4. View response and assertions in the **Response panel** and logs in the **Script Logs**.

docs/core-features-section/voiden-blocks/rest-blocks/xml-block.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ And when your tags get tangled? Hit **Prettify** in the top-right corner to form
1818

1919
1. Type `/xml` to add an **XML Block** payload to your Voiden file
2020

21-
![xml](/img/plugins/openapi-collection/xml-pre.png)
21+
![xml](/img/plugins/socket/xml-pre.png)
2222

2323
2. Paste in (or type) the sample **XML**
2424
3. Hit **Cmd + Enter** (Mac) or **Ctrl + Enter** (Windows/Linux) to run the request
2525
**or** click the **green Play button** in the toolbar.
2626

2727
---
2828

29-
![xml](/img/plugins/openapi-collection/xml-post.gif)
29+
![xml](/img/plugins/socket/xml-post.gif)
3030
> **Pro Tip:** Want to comment out a line without overkill?
3131
> Use **Cmd + /** (Mac) or **Ctrl + /** (Windows/Linux) to comment out an XML line you don't need for that payload.
3232
> It’ll stay visible but won’t be sent with the request.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
id: voiden-editor
3+
title: The Voiden Editor
4+
sidebar_label: Voiden Editor
5+
---
6+
7+
# The Voiden Editor
8+
9+
Voiden ships with its own custom editor, built on top of **Tiptap**. It looks like a rich-text editor, but everything is saved as clean **Markdown** underneath — file-based, Git-friendly, and readable outside Voiden.
10+
11+
![Voiden Editor](/img/geetingstarted/voideneditor.png)
12+
13+
---
14+
15+
## Block-Based Editing
16+
17+
The editor is structured around **blocks**. Instead of one long file, you insert purpose-specific blocks:
18+
19+
- Request blocks
20+
- Variable blocks
21+
- Assertion blocks
22+
- Script blocks
23+
- Markdown blocks
24+
25+
Each block has a clear role, making files easy to scan even as they grow.
26+
27+
---
28+
29+
## Write and Document Together
30+
31+
Requests, explanations, response comments, and usage notes all live in the same file — right next to each other.
32+
33+
No context switching. No separate tools.
34+
35+
---
36+
37+
## Keyboard-Friendly
38+
39+
Insert blocks with slash commands (e.g. `/endpoint`, `/headers`, `/json`), reorder them quickly, and run requests without leaving the editor.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
id: overview
3+
title: Overview
4+
sidebar_label: Overview
5+
sidebar_position: 1
6+
---
7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
10+
# <div style={{display:"flex",alignItems:"center"}}> Voiden Scripting <small style={{alignSelf:"start",fontSize:"12px",marginLeft:"10px",padding:"5px",background:"#8a5cf67d",display:"flex",alignItems:"cetner",gap:"5px",borderRadius:"10px"}}><img src="/img/flask-conical.svg" width="14" /> Beta only</small></div>
11+
12+
> **Note:** This feature is currently in **Beta**.
13+
14+
Voiden Scripting lets you run **JavaScript** or **Python** code as part of your request lifecycle, using the exposed `voiden` API.
15+
16+
Scripts run at two stages:
17+
18+
- [**Pre Script**](/docs/plugins/core-plugins/pre-post%20script/pre-script) — runs before the request is sent
19+
- [**Post Script**](/docs/plugins/core-plugins/pre-post%20script/post-script) — runs after the response is received
20+
21+
Both stages share the same `voiden` API.
22+
23+
Scripts run in an isolated environment. You have full freedom to use any library or perform any operation — Voiden simply exposes the `voiden` API on top of that.
24+
25+
---
26+
27+
## Blocks
28+
29+
Voiden Scripting introduces two blocks you can add to your `.void` file:
30+
31+
| Block | Description |
32+
|---|---|
33+
| [**Pre-Script**](/docs/plugins/core-plugins/pre-post%20script/pre-script) | Runs before the request is sent. Use it to modify headers, body, params, or cancel the request entirely. |
34+
| [**Post-Script**](/docs/plugins/core-plugins/pre-post%20script/post-script) | Runs after the response is received. Use it to assert values, extract data, and store variables for later requests. |
35+
36+
---
37+
38+
## How Scripts Run
39+
40+
Voiden runs your scripts in an isolated environment so they can't interfere with the app. The way this works differs slightly between languages.
41+
42+
**JavaScript** scripts are sent to a separate Node.js process. The `voiden` API (env, variables) communicates back to the app via message passing, so every API call returns a Promise. This is why you need `await`.
43+
44+
**Python** scripts also run in a separate process, but before the script starts, Voiden pre-loads all your environment variables and runtime variables and passes them in directly. So the `voiden` API is just plain synchronous method calls — no `await` needed.
45+
46+
<Tabs>
47+
<TabItem value="js" label="JavaScript" default>
48+
```js
49+
const token = await voiden.env.get("TOKEN");
50+
const userId = await voiden.variables.get("userId");
51+
```
52+
</TabItem>
53+
<TabItem value="py" label="Python">
54+
```py
55+
token = voiden.env.get("TOKEN")
56+
user_id = voiden.variables.get("userId")
57+
```
58+
</TabItem>
59+
</Tabs>
60+
61+
---
62+
63+
## Environment Variables
64+
65+
Environment variables are read-only values configured in your active environment.
66+
67+
<Tabs>
68+
<TabItem value="js" label="JavaScript" default>
69+
```js
70+
const token = await voiden.env.get("API_TOKEN");
71+
```
72+
</TabItem>
73+
<TabItem value="py" label="Python">
74+
```py
75+
token = voiden.env.get("API_TOKEN")
76+
```
77+
</TabItem>
78+
</Tabs>
79+
80+
---
81+
82+
## Runtime Variables
83+
84+
Runtime variables are dynamic values you can create, read, and update during execution. They are useful for passing data between requests.
85+
86+
<Tabs>
87+
<TabItem value="js" label="JavaScript" default>
88+
```js
89+
await voiden.variables.set("key", "value");
90+
const val = await voiden.variables.get("key");
91+
```
92+
</TabItem>
93+
<TabItem value="py" label="Python">
94+
```py
95+
voiden.variables.set("key", "value")
96+
val = voiden.variables.get("key")
97+
```
98+
</TabItem>
99+
</Tabs>
100+
101+
![pre-runtime](/img/plugins/pre-post/output.gif)
102+
103+
---
104+
105+
## Logging
106+
107+
Logs appear in Voiden's UI and help you debug, trace flow, or monitor values during script execution.
108+
109+
<Tabs>
110+
<TabItem value="js" label="JavaScript" default>
111+
```js
112+
voiden.log("message");
113+
voiden.log("info", "pre-script ran");
114+
voiden.log("warn", "token missing");
115+
voiden.log("error", "request aborted");
116+
voiden.log("debug", "body:", voiden.request.body);
117+
```
118+
</TabItem>
119+
<TabItem value="py" label="Python">
120+
```py
121+
voiden.log("message")
122+
voiden.log("info", "pre-script ran")
123+
voiden.log("warn", "token missing")
124+
voiden.log("error", "request aborted")
125+
voiden.log("debug", "body:", voiden.request.body)
126+
```
127+
</TabItem>
128+
</Tabs>
129+
130+
![Voiden Script Log](/img/plugins/pre-post/voiden-log.gif)
131+
132+
**Supported levels:** `log` · `info` · `debug` · `warn` · `error`
133+
134+
---
135+
136+
## Assertions
137+
138+
Assertions let you validate values and surface pass/fail results in the Response panel.
139+
140+
![Voiden Script Assertion](/img/plugins/pre-post/voiden-script.png)
141+
142+
```js
143+
voiden.assert(actual, operator, expectedValue, message);
144+
```
145+
146+
| Parameter | Description |
147+
|---|---|
148+
| `actual` | The value to test (e.g. `voiden.response.status`) |
149+
| `operator` | Comparison operator (e.g. `"=="`, `"contains"`, `"greater"`) |
150+
| `expectedValue` | The value you expect |
151+
| `message` | (Optional) Label shown in the assertion result |
152+
153+
<Tabs>
154+
<TabItem value="js" label="JavaScript" default>
155+
```js
156+
voiden.assert(voiden.response.status, "==", 200, "Status should be 200");
157+
voiden.assert(voiden.response.body.name, "contains", "Voiden", "Name check");
158+
```
159+
</TabItem>
160+
<TabItem value="py" label="Python">
161+
```py
162+
voiden.assert(voiden.response.status, "==", 200, "Status should be 200")
163+
voiden.assert(voiden.response.body.name, "contains", "Voiden", "Name check")
164+
```
165+
</TabItem>
166+
</Tabs>

0 commit comments

Comments
 (0)