Fetch module provides utilities for parsing curl-style arguments, building Web API Request objects, and parsing Response objects. Itβs designed for implementing HTTP gateways and REST API integrations.
Functions
parseArgv
Parses curl-style argv into a structured fetch input.Array of command-line arguments in curl style
Structured input object with path, method, headers, body, and query parameters
Example
Reserved Flags
--method/-X- HTTP method (GET, POST, etc.)--data/-d- Request body--body- Request body (alternative)--header/-H- HTTP header (format:Name: Value)
buildRequest
Constructs a standard Web API Request from a FetchInput.Structured fetch input object
Standard Web API Request object
Example
parseResponse
Parses a fetch Response into structured output.Web API Response object
Structured output with status, headers, and parsed data
Example
isStreamingResponse
Returns true if the response body is a stream that should be consumed incrementally.Web API Response object
true if the response is NDJSON streaming, false otherwiseExample
parseStreamingResponse
Parses a streaming response body as an async generator of parsed NDJSON chunks.Web API Response object with
content-type: application/x-ndjsonAsync generator yielding parsed NDJSON chunks
Example
Types
FetchInput
Structured input parsed from curl-style argv.Request body string
Web API Headers object
HTTP method (uppercase)
Request path (starts with
/)Query parameters
FetchOutput
Structured output from a fetch Response.Parsed response data (JSON object or text string)
Response headers
true for 2xx status codesHTTP status code
Usage Patterns
Building an HTTP Gateway
Handling Streaming Responses
Related
- Openapi - Generate commands from OpenAPI specs
- Mounting APIs - Guide to mounting REST APIs

