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.string[]
required
Array of command-line arguments in curl style
FetchInput
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.FetchInput
required
Structured fetch input object
Request
Standard Web API Request object
Example
parseResponse
Parses a fetch Response into structured output.Response
required
Web API Response object
Promise<FetchOutput>
Structured output with status, headers, and parsed data
Example
isStreamingResponse
Returns true if the response body is a stream that should be consumed incrementally.Response
required
Web API Response object
boolean
true if the response is NDJSON streaming, false otherwiseExample
parseStreamingResponse
Parses a streaming response body as an async generator of parsed NDJSON chunks.Response
required
Web API Response object with
content-type: application/x-ndjsonAsyncGenerator<unknown, void, unknown>
Async generator yielding parsed NDJSON chunks
Example
Types
FetchInput
Structured input parsed from curl-style argv.string | undefined
required
Request body string
Headers
required
Web API Headers object
string
required
HTTP method (uppercase)
string
required
Request path (starts with
/)URLSearchParams
required
Query parameters
FetchOutput
Structured output from a fetch Response.unknown
required
Parsed response data (JSON object or text string)
Headers
required
Response headers
boolean
required
true for 2xx status codesnumber
required
HTTP 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

