Skip to main content
The 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.
argv
string[]
required
Array of command-line arguments in curl style
return
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)
All other flags become query parameters.

buildRequest

Constructs a standard Web API Request from a FetchInput.
input
FetchInput
required
Structured fetch input object
return
Request
Standard Web API Request object

Example

parseResponse

Parses a fetch Response into structured output.
response
Response
required
Web API Response object
return
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
Response
required
Web API Response object
return
boolean
true if the response is NDJSON streaming, false otherwise

Example

parseStreamingResponse

Parses a streaming response body as an async generator of parsed NDJSON chunks.
response
Response
required
Web API Response object with content-type: application/x-ndjson
return
AsyncGenerator<unknown, void, unknown>
Async generator yielding parsed NDJSON chunks

Example

Types

FetchInput

Structured input parsed from curl-style argv.
body
string | undefined
required
Request body string
headers
Headers
required
Web API Headers object
method
string
required
HTTP method (uppercase)
path
string
required
Request path (starts with /)
query
URLSearchParams
required
Query parameters

FetchOutput

Structured output from a fetch Response.
data
unknown
required
Parsed response data (JSON object or text string)
headers
Headers
required
Response headers
ok
boolean
required
true for 2xx status codes
status
number
required
HTTP status code

Usage Patterns

Building an HTTP Gateway

Handling Streaming Responses