05 - Sending Requests
End-to-End Flow
- User edits request state in renderer.
- Renderer builds RequestPayload.
- Renderer invokes desktopApi.sendRequest through preload IPC.
- Electron main process validates and sends network request.
- Main process returns response payload or structured error.
Request Payload Structure
RequestPayload includes:
- method
- url
- contextFolderPath (optional)
- headers
- body
- preRequestScript/testScript (optional; currently disabled by flag)
Defined in contracts model.
URL and Params Synchronization
In renderer state reducer:
- Editing URL parses query params into editable rows.
- Editing param rows rebuilds URL query string.
This keeps URL text and param editor in sync.
Header and Body Construction in Main Process
Main process buildRequestInit logic:
- Trims header keys
- Skips empty header keys
- Sends body only when method is not GET and body text is non-empty
- Auto-adds content-type if body exists and header not already present
Folder Variable Resolution
Before sending, main process resolves URL placeholders when contextFolderPath is provided:
- Pattern:
{{variableName}} - Value source: inherited folder variable files
Unresolved placeholders remain unchanged.
Network Execution
Main process performs fetch in Node context, not renderer context.
Benefits:
- Avoids browser-level CORS restrictions in renderer
- Centralized error capture and response normalization
Response Payload Returned to Renderer
ResponsePayload includes:
- status
- statusText
- headers map
- body text
- durationMs
- final URL
- optional testResults/scriptError fields
Error Model
When request fails, SendRequestResult includes:
- ok false
- error message
- optional error details
- durationMs
Error details attempt to expose cause code/message when available.
Response Formatting in UI
Renderer formatter behavior:
- Checks content-type headers for json
- Falls back to payload shape heuristic (starts with
{or[) - Pretty-prints JSON with 2-space indentation
- Falls back to raw text when parse fails
Practical Notes
- Invalid or empty URL triggers validation error before fetch.
- Method/body behavior follows current implementation rules.
- Always test requests after import because imported examples may need environment-specific tuning.