@xano/developer-mcp 1.0.20 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -19
- package/dist/index.js +4 -227
- package/dist/meta_api_docs/format.d.ts +16 -1
- package/dist/meta_api_docs/format.js +24 -6
- package/dist/meta_api_docs/format.test.d.ts +1 -0
- package/dist/meta_api_docs/format.test.js +274 -0
- package/dist/meta_api_docs/index.test.d.ts +1 -0
- package/dist/meta_api_docs/index.test.js +128 -0
- package/dist/meta_api_docs/types.test.d.ts +1 -0
- package/dist/meta_api_docs/types.test.js +132 -0
- package/dist/run_api_docs/format.d.ts +1 -0
- package/dist/run_api_docs/format.js +3 -170
- package/dist/run_api_docs/format.test.d.ts +1 -0
- package/dist/run_api_docs/format.test.js +86 -0
- package/dist/run_api_docs/index.test.d.ts +1 -0
- package/dist/run_api_docs/index.test.js +127 -0
- package/dist/templates/init-workspace.js +4 -4
- package/dist/templates/xanoscript-index.d.ts +3 -1
- package/dist/templates/xanoscript-index.js +54 -51
- package/dist/xanoscript.d.ts +41 -0
- package/dist/xanoscript.js +261 -0
- package/dist/xanoscript.test.d.ts +1 -0
- package/dist/xanoscript.test.js +303 -0
- package/dist/xanoscript_docs/README.md +53 -37
- package/dist/xanoscript_docs/agents.md +1 -1
- package/dist/xanoscript_docs/apis.md +6 -3
- package/dist/xanoscript_docs/branch.md +239 -0
- package/dist/xanoscript_docs/functions.md +6 -6
- package/dist/xanoscript_docs/integrations.md +43 -1
- package/dist/xanoscript_docs/middleware.md +321 -0
- package/dist/xanoscript_docs/performance.md +1 -1
- package/dist/xanoscript_docs/realtime.md +113 -1
- package/dist/xanoscript_docs/tasks.md +2 -2
- package/dist/xanoscript_docs/tools.md +3 -3
- package/dist/xanoscript_docs/types.md +25 -8
- package/dist/xanoscript_docs/workspace.md +209 -0
- package/dist/xanoscript_docs_auto/README.md +119 -0
- package/dist/xanoscript_docs_auto/agents.md +446 -0
- package/dist/xanoscript_docs_auto/apis.md +517 -0
- package/dist/xanoscript_docs_auto/control-flow.md +543 -0
- package/dist/xanoscript_docs_auto/database.md +551 -0
- package/dist/xanoscript_docs_auto/debugging.md +527 -0
- package/dist/xanoscript_docs_auto/filters.md +464 -0
- package/dist/xanoscript_docs_auto/functions.md +431 -0
- package/dist/xanoscript_docs_auto/integrations.md +657 -0
- package/dist/xanoscript_docs_auto/mcp-servers.md +408 -0
- package/dist/xanoscript_docs_auto/operators.md +368 -0
- package/dist/xanoscript_docs_auto/syntax.md +287 -0
- package/dist/xanoscript_docs_auto/tables.md +447 -0
- package/dist/xanoscript_docs_auto/tasks.md +479 -0
- package/dist/xanoscript_docs_auto/testing.md +574 -0
- package/dist/xanoscript_docs_auto/tools.md +485 -0
- package/dist/xanoscript_docs_auto/triggers.md +595 -0
- package/dist/xanoscript_docs_auto/types.md +323 -0
- package/dist/xanoscript_docs_auto/variables.md +462 -0
- package/dist/xanoscript_docs_auto/version.json +5 -0
- package/package.json +6 -2
|
@@ -15,6 +15,10 @@ XanoScript is the declarative scripting language for [Xano](https://xano.com), a
|
|
|
15
15
|
| `tool` | `tools/**/*.xs` | Tools for AI agents |
|
|
16
16
|
| `mcp_server` | `mcp_servers/**/*.xs` | MCP server definitions |
|
|
17
17
|
| `addon` | `addons/*.xs` | Subqueries for related data |
|
|
18
|
+
| `middleware` | `middleware/**/*.xs` | Request/response interceptors |
|
|
19
|
+
| `branch` | `branch.xs` | Branch-level configuration |
|
|
20
|
+
| `workspace` | `workspace.xs` | Workspace-level configuration |
|
|
21
|
+
| `realtime_channel` | Configuration | Realtime channel settings |
|
|
18
22
|
|
|
19
23
|
**Important:** Each `.xs` file must contain exactly one definition. You cannot define multiple tables, functions, queries, or other constructs in a single file.
|
|
20
24
|
|
|
@@ -22,6 +26,8 @@ XanoScript is the declarative scripting language for [Xano](https://xano.com), a
|
|
|
22
26
|
|
|
23
27
|
```
|
|
24
28
|
project/
|
|
29
|
+
├── workspace.xs // Workspace configuration (env vars, preferences)
|
|
30
|
+
├── branch.xs // Branch configuration (middleware, history)
|
|
25
31
|
├── tables/ // Database table schemas
|
|
26
32
|
├── functions/ // Reusable functions (supports subfolders)
|
|
27
33
|
├── apis/
|
|
@@ -31,6 +37,7 @@ project/
|
|
|
31
37
|
├── agents/ // AI agents
|
|
32
38
|
├── tools/ // AI tools
|
|
33
39
|
├── mcp_servers/ // MCP server definitions
|
|
40
|
+
├── middleware/ // Request/response interceptors
|
|
34
41
|
├── addons/ // Query addons
|
|
35
42
|
├── static/ // Frontend files (HTML, CSS, JS)
|
|
36
43
|
└── run/ // Job and service configurations
|
|
@@ -73,6 +80,8 @@ $db.table.field // Database field reference (in queries)
|
|
|
73
80
|
$this // Current item in loops/maps
|
|
74
81
|
```
|
|
75
82
|
|
|
83
|
+
**Note:** `$response` is a reserved word and cannot be used as a variable name.
|
|
84
|
+
|
|
76
85
|
### Comments
|
|
77
86
|
```xs
|
|
78
87
|
// Single-line comment
|
|
@@ -103,54 +112,61 @@ This helps AI tools apply the correct documentation based on the file being edit
|
|
|
103
112
|
|
|
104
113
|
## Documentation Index
|
|
105
114
|
|
|
106
|
-
Use `xanoscript_docs({
|
|
115
|
+
Use `xanoscript_docs({ topic: "<topic>" })` to retrieve documentation.
|
|
107
116
|
|
|
108
117
|
### Core Language
|
|
109
|
-
| Topic |
|
|
110
|
-
|
|
111
|
-
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
|
118
|
+
| Topic | Description |
|
|
119
|
+
|-------|-------------|
|
|
120
|
+
| `syntax` | Expressions, operators, filters, system variables |
|
|
121
|
+
| `types` | Data types, validation, input blocks |
|
|
122
|
+
| `functions` | Reusable function stacks, async, loops |
|
|
123
|
+
| `schema` | Runtime schema parsing and validation |
|
|
115
124
|
|
|
116
125
|
### Data
|
|
117
|
-
| Topic |
|
|
118
|
-
|
|
119
|
-
|
|
|
120
|
-
|
|
|
121
|
-
|
|
|
122
|
-
|
|
|
126
|
+
| Topic | Description |
|
|
127
|
+
|-------|-------------|
|
|
128
|
+
| `tables` | Database schema definitions with indexes and relationships |
|
|
129
|
+
| `database` | All db.* operations: query, get, add, edit, patch, delete |
|
|
130
|
+
| `addons` | Reusable subqueries for fetching related data |
|
|
131
|
+
| `streaming` | Streaming data from files, requests, and responses |
|
|
123
132
|
|
|
124
133
|
### APIs & Endpoints
|
|
125
|
-
| Topic |
|
|
126
|
-
|
|
127
|
-
|
|
|
128
|
-
|
|
|
129
|
-
|
|
|
130
|
-
|
|
|
134
|
+
| Topic | Description |
|
|
135
|
+
|-------|-------------|
|
|
136
|
+
| `apis` | HTTP endpoint definitions with authentication and CRUD patterns |
|
|
137
|
+
| `tasks` | Scheduled and cron jobs |
|
|
138
|
+
| `triggers` | Event-driven handlers (table, realtime, workspace, agent, MCP) |
|
|
139
|
+
| `realtime` | Real-time channels and events for push updates |
|
|
131
140
|
|
|
132
141
|
### AI & Agents
|
|
133
|
-
| Topic |
|
|
134
|
-
|
|
135
|
-
|
|
|
136
|
-
|
|
|
137
|
-
|
|
|
142
|
+
| Topic | Description |
|
|
143
|
+
|-------|-------------|
|
|
144
|
+
| `agents` | AI agent configuration with LLM providers and tools |
|
|
145
|
+
| `tools` | AI tools for agents and MCP servers |
|
|
146
|
+
| `mcp-servers` | MCP server definitions exposing tools |
|
|
138
147
|
|
|
139
148
|
### Integrations
|
|
140
|
-
| Topic |
|
|
141
|
-
|
|
142
|
-
|
|
|
149
|
+
| Topic | Description |
|
|
150
|
+
|-------|-------------|
|
|
151
|
+
| `integrations` | Cloud storage, Redis, security, and external APIs |
|
|
152
|
+
|
|
153
|
+
### Configuration
|
|
154
|
+
| Topic | Description |
|
|
155
|
+
|-------|-------------|
|
|
156
|
+
| `workspace` | Workspace-level settings: environment variables, preferences, realtime |
|
|
157
|
+
| `branch` | Branch-level settings: middleware, history retention, visual styling |
|
|
158
|
+
| `middleware` | Request/response interceptors for functions, queries, tasks, and tools |
|
|
143
159
|
|
|
144
160
|
### Development
|
|
145
|
-
| Topic |
|
|
146
|
-
|
|
147
|
-
|
|
|
148
|
-
|
|
|
149
|
-
|
|
|
150
|
-
|
|
|
161
|
+
| Topic | Description |
|
|
162
|
+
|-------|-------------|
|
|
163
|
+
| `testing` | Unit tests, mocks, and assertions |
|
|
164
|
+
| `debugging` | Logging, inspecting, and debugging XanoScript execution |
|
|
165
|
+
| `frontend` | Static frontend development and deployment |
|
|
166
|
+
| `run` | Run job and service configurations for the Xano Job Runner |
|
|
151
167
|
|
|
152
168
|
### Best Practices
|
|
153
|
-
| Topic |
|
|
154
|
-
|
|
155
|
-
|
|
|
156
|
-
|
|
|
169
|
+
| Topic | Description |
|
|
170
|
+
|-------|-------------|
|
|
171
|
+
| `performance` | Performance optimization best practices |
|
|
172
|
+
| `security` | Security best practices for authentication and authorization |
|
|
@@ -86,7 +86,7 @@ query "products" verb=GET {
|
|
|
86
86
|
|
|
87
87
|
## Input Block
|
|
88
88
|
|
|
89
|
-
For complete type and filter reference, use `xanoscript_docs({
|
|
89
|
+
For complete type and filter reference, use `xanoscript_docs({ topic: "types" })`.
|
|
90
90
|
|
|
91
91
|
### Empty Input Blocks
|
|
92
92
|
|
|
@@ -345,11 +345,14 @@ stack {
|
|
|
345
345
|
|
|
346
346
|
## Error Handling
|
|
347
347
|
|
|
348
|
-
For complete error handling reference, use `xanoscript_docs({
|
|
348
|
+
For complete error handling reference, use `xanoscript_docs({ topic: "syntax" })`.
|
|
349
349
|
|
|
350
350
|
| Type | HTTP Status |
|
|
351
351
|
|------|-------------|
|
|
352
|
-
| `inputerror` | 400 |
|
|
352
|
+
| `inputerror` | 400 |
|
|
353
|
+
| `accessdenied` | 403 |
|
|
354
|
+
| `notfound` | 404 |
|
|
355
|
+
| `standard` | 500 |
|
|
353
356
|
|
|
354
357
|
---
|
|
355
358
|
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "branch.xs"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Branch Configuration
|
|
6
|
+
|
|
7
|
+
Configure branch-level settings including middleware, history retention, and visual styling.
|
|
8
|
+
|
|
9
|
+
## Quick Reference
|
|
10
|
+
|
|
11
|
+
```xs
|
|
12
|
+
branch "<name>" {
|
|
13
|
+
color = "#hex"
|
|
14
|
+
description = "Branch description"
|
|
15
|
+
middleware = { ... }
|
|
16
|
+
history = { ... }
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Attributes
|
|
21
|
+
| Attribute | Type | Required | Description |
|
|
22
|
+
|-----------|------|----------|-------------|
|
|
23
|
+
| `color` | text | Yes | Hex color code for branch identification |
|
|
24
|
+
| `description` | text | No | Human-readable branch description |
|
|
25
|
+
| `middleware` | object | No | Pre/post middleware configuration |
|
|
26
|
+
| `history` | object | No | Request history retention settings |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Basic Structure
|
|
31
|
+
|
|
32
|
+
```xs
|
|
33
|
+
branch "production" {
|
|
34
|
+
color = "#22c55e"
|
|
35
|
+
description = "Production environment"
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Middleware Configuration
|
|
42
|
+
|
|
43
|
+
Configure middleware to run before (pre) and after (post) different construct types.
|
|
44
|
+
|
|
45
|
+
### Syntax
|
|
46
|
+
|
|
47
|
+
```xs
|
|
48
|
+
branch "production" {
|
|
49
|
+
color = "#22c55e"
|
|
50
|
+
|
|
51
|
+
middleware = {
|
|
52
|
+
function: {
|
|
53
|
+
pre: ["auth_check", "rate_limit"],
|
|
54
|
+
post: ["audit_log"]
|
|
55
|
+
},
|
|
56
|
+
query: {
|
|
57
|
+
pre: ["auth_check", "rate_limit"],
|
|
58
|
+
post: ["audit_log", "cache_response"]
|
|
59
|
+
},
|
|
60
|
+
task: {
|
|
61
|
+
pre: ["task_lock"],
|
|
62
|
+
post: ["task_cleanup"]
|
|
63
|
+
},
|
|
64
|
+
tool: {
|
|
65
|
+
pre: ["tool_auth"],
|
|
66
|
+
post: ["tool_log"]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Middleware Targets
|
|
73
|
+
|
|
74
|
+
| Target | Description |
|
|
75
|
+
|--------|-------------|
|
|
76
|
+
| `function` | Applies to all function calls |
|
|
77
|
+
| `query` | Applies to all API endpoints |
|
|
78
|
+
| `task` | Applies to scheduled tasks |
|
|
79
|
+
| `tool` | Applies to AI agent tools |
|
|
80
|
+
|
|
81
|
+
### Pre vs Post Middleware
|
|
82
|
+
|
|
83
|
+
| Type | Execution | Use Cases |
|
|
84
|
+
|------|-----------|-----------|
|
|
85
|
+
| `pre` | Before main logic | Authentication, rate limiting, validation |
|
|
86
|
+
| `post` | After main logic | Logging, caching, response transformation |
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## History Configuration
|
|
91
|
+
|
|
92
|
+
Control how many historical executions are retained for debugging and auditing.
|
|
93
|
+
|
|
94
|
+
### Syntax
|
|
95
|
+
|
|
96
|
+
```xs
|
|
97
|
+
branch "production" {
|
|
98
|
+
color = "#22c55e"
|
|
99
|
+
|
|
100
|
+
history = {
|
|
101
|
+
function: 100,
|
|
102
|
+
query: 1000,
|
|
103
|
+
task: 100,
|
|
104
|
+
tool: 100,
|
|
105
|
+
trigger: 100,
|
|
106
|
+
middleware: 10
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### History Values
|
|
112
|
+
|
|
113
|
+
| Value | Description |
|
|
114
|
+
|-------|-------------|
|
|
115
|
+
| `false` | Disable history (no retention) |
|
|
116
|
+
| `10` | Keep last 10 executions |
|
|
117
|
+
| `100` | Keep last 100 executions |
|
|
118
|
+
| `1000` | Keep last 1000 executions |
|
|
119
|
+
| `10000` | Keep last 10000 executions |
|
|
120
|
+
| `"all"` | Keep all executions (use with caution) |
|
|
121
|
+
|
|
122
|
+
### History Targets
|
|
123
|
+
|
|
124
|
+
| Target | Description |
|
|
125
|
+
|--------|-------------|
|
|
126
|
+
| `function` | Function execution history |
|
|
127
|
+
| `query` | API endpoint request history |
|
|
128
|
+
| `task` | Scheduled task execution history |
|
|
129
|
+
| `tool` | AI tool invocation history |
|
|
130
|
+
| `trigger` | Trigger execution history |
|
|
131
|
+
| `middleware` | Middleware execution history |
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Common Patterns
|
|
136
|
+
|
|
137
|
+
### Development Branch
|
|
138
|
+
|
|
139
|
+
```xs
|
|
140
|
+
branch "development" {
|
|
141
|
+
color = "#3b82f6"
|
|
142
|
+
description = "Development environment with full debugging"
|
|
143
|
+
|
|
144
|
+
history = {
|
|
145
|
+
function: "all",
|
|
146
|
+
query: "all",
|
|
147
|
+
task: "all",
|
|
148
|
+
tool: "all",
|
|
149
|
+
trigger: "all",
|
|
150
|
+
middleware: "all"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Staging Branch
|
|
156
|
+
|
|
157
|
+
```xs
|
|
158
|
+
branch "staging" {
|
|
159
|
+
color = "#f59e0b"
|
|
160
|
+
description = "Staging environment for testing"
|
|
161
|
+
|
|
162
|
+
middleware = {
|
|
163
|
+
query: {
|
|
164
|
+
pre: ["auth_check"],
|
|
165
|
+
post: ["audit_log"]
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
history = {
|
|
170
|
+
function: 1000,
|
|
171
|
+
query: 1000,
|
|
172
|
+
task: 100,
|
|
173
|
+
tool: 100,
|
|
174
|
+
trigger: 100,
|
|
175
|
+
middleware: 100
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Production Branch
|
|
181
|
+
|
|
182
|
+
```xs
|
|
183
|
+
branch "production" {
|
|
184
|
+
color = "#22c55e"
|
|
185
|
+
description = "Production environment"
|
|
186
|
+
|
|
187
|
+
middleware = {
|
|
188
|
+
function: {
|
|
189
|
+
pre: ["auth_check", "rate_limit"],
|
|
190
|
+
post: ["audit_log"]
|
|
191
|
+
},
|
|
192
|
+
query: {
|
|
193
|
+
pre: ["auth_check", "rate_limit", "security_check"],
|
|
194
|
+
post: ["audit_log", "cache_response"]
|
|
195
|
+
},
|
|
196
|
+
task: {
|
|
197
|
+
pre: ["task_lock"],
|
|
198
|
+
post: ["audit_log"]
|
|
199
|
+
},
|
|
200
|
+
tool: {
|
|
201
|
+
pre: ["auth_check"],
|
|
202
|
+
post: ["audit_log"]
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
history = {
|
|
207
|
+
function: 100,
|
|
208
|
+
query: 100,
|
|
209
|
+
task: 100,
|
|
210
|
+
tool: 100,
|
|
211
|
+
trigger: 100,
|
|
212
|
+
middleware: false
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## File Location
|
|
220
|
+
|
|
221
|
+
Branch configuration files are typically named `branch.xs` and placed at the workspace root or in a dedicated configuration directory.
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
project/
|
|
225
|
+
├── branch.xs // Branch configuration
|
|
226
|
+
├── tables/
|
|
227
|
+
├── functions/
|
|
228
|
+
└── apis/
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Best Practices
|
|
234
|
+
|
|
235
|
+
1. **Use descriptive colors** - Green for production, blue for development, yellow for staging
|
|
236
|
+
2. **Limit production history** - Excessive history impacts performance and storage
|
|
237
|
+
3. **Apply security middleware in production** - Rate limiting, auth checks, audit logging
|
|
238
|
+
4. **Disable middleware history in production** - Reduces noise and storage
|
|
239
|
+
5. **Enable full history in development** - Aids debugging and testing
|
|
@@ -72,7 +72,7 @@ Reference with path: `function.run "math/add" { ... }`
|
|
|
72
72
|
|
|
73
73
|
## Input Block
|
|
74
74
|
|
|
75
|
-
For complete type and filter reference, use `xanoscript_docs({
|
|
75
|
+
For complete type and filter reference, use `xanoscript_docs({ topic: "types" })`.
|
|
76
76
|
|
|
77
77
|
```xs
|
|
78
78
|
input {
|
|
@@ -188,7 +188,7 @@ stack {
|
|
|
188
188
|
|
|
189
189
|
### Error Handling
|
|
190
190
|
|
|
191
|
-
For complete error handling reference (preconditions, try-catch, throw, early return), use `xanoscript_docs({
|
|
191
|
+
For complete error handling reference (preconditions, try-catch, throw, early return), use `xanoscript_docs({ topic: "syntax" })`.
|
|
192
192
|
|
|
193
193
|
---
|
|
194
194
|
|
|
@@ -342,7 +342,7 @@ stack {
|
|
|
342
342
|
async = true
|
|
343
343
|
} as $request
|
|
344
344
|
|
|
345
|
-
await $request as $
|
|
345
|
+
await $request as $result
|
|
346
346
|
}
|
|
347
347
|
```
|
|
348
348
|
|
|
@@ -372,9 +372,9 @@ stack {
|
|
|
372
372
|
// All three requests complete before continuing
|
|
373
373
|
var $combined {
|
|
374
374
|
value = {
|
|
375
|
-
users: $users.
|
|
376
|
-
products: $products.
|
|
377
|
-
orders: $orders.
|
|
375
|
+
users: $users.response.result,
|
|
376
|
+
products: $products.response.result,
|
|
377
|
+
orders: $orders.response.result
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
}
|
|
@@ -587,6 +587,8 @@ util.send_email {
|
|
|
587
587
|
|
|
588
588
|
## External APIs
|
|
589
589
|
|
|
590
|
+
Make HTTP requests to external APIs.
|
|
591
|
+
|
|
590
592
|
```xs
|
|
591
593
|
api.request {
|
|
592
594
|
url = "https://api.example.com/data"
|
|
@@ -594,7 +596,47 @@ api.request {
|
|
|
594
596
|
params = { key: "value" }
|
|
595
597
|
headers = []|push:("Authorization: Bearer " ~ $env.API_KEY)
|
|
596
598
|
timeout = 30
|
|
597
|
-
} as $
|
|
599
|
+
} as $api_result
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
### Response Structure
|
|
603
|
+
|
|
604
|
+
The `api.request` statement returns an object with both request and response details:
|
|
605
|
+
|
|
606
|
+
```json
|
|
607
|
+
{
|
|
608
|
+
"request": {
|
|
609
|
+
"url": "", // The URL that was requested
|
|
610
|
+
"method": "", // HTTP method used (GET, POST, etc.)
|
|
611
|
+
"headers": [], // Array of request headers sent
|
|
612
|
+
"params": [] // Parameters sent with the request
|
|
613
|
+
},
|
|
614
|
+
"response": {
|
|
615
|
+
"headers": [], // Array of response headers received
|
|
616
|
+
"result": "", // Response body (can be any format: JSON, string, null, boolean, etc.)
|
|
617
|
+
"status": 200 // HTTP status code
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
### Accessing Response Data
|
|
623
|
+
|
|
624
|
+
```xs
|
|
625
|
+
api.request {
|
|
626
|
+
url = "https://api.example.com/users"
|
|
627
|
+
method = "GET"
|
|
628
|
+
} as $api_result
|
|
629
|
+
|
|
630
|
+
// Access the response body
|
|
631
|
+
var $data { value = $api_result.response.result }
|
|
632
|
+
|
|
633
|
+
// Check status code
|
|
634
|
+
if ($api_result.response.status != 200) {
|
|
635
|
+
precondition { false } with { message = "API request failed" }
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// Access a specific header
|
|
639
|
+
var $content_type { value = $api_result.response.headers|first }
|
|
598
640
|
```
|
|
599
641
|
|
|
600
642
|
---
|