API design decisions
A few naming and ergonomics choices are intentional and locked for stability. They are documented here so the asymmetries do not read as accidental.
searchParamsvsparams. Query values usesearchParams(plussearchSchema); path values useparams(plusparamsSchema). ThesearchParamskey deliberately mirrors the web platform'sURL.searchParams/URLSearchParamsand the equivalent option in ky, so the value key (searchParams) and its schema (searchSchema) use slightly different stems. Platform alignment is preferred over internal symmetry.json/form/body. Structured bodies go throughjson(validated againstbodySchema) orform;bodyis the raw escape hatch (string,Blob,ArrayBuffer, typed array,ReadableStream) sent as-is with no validation orContent-Typeinference. Exactly one may be set per request; none is accepted at instance level.responseTypeis per-call only.responseTypelives on the per-request options, not oncreate()/extend()instance options. It changes the return type of a call ('blob'givesBlob,'sse'givesAsyncIterable<MessageEvent>, and so on), which cannot be expressed at instance-creation time without losing type safety. Set it on each call instead.ValifetchError.causeisunknown. Matching the standardError.cause, thecauseoption accepts any thrown value, not just anError, so non-Errorthrows pass through without wrapping.- Hook signatures stay positional, following ky 1.x. (ky 2 moved to state-object arguments; valifetch deliberately does not.)
beforeRequest(request, options),afterResponse(request, options, response),afterParseResponse(data, response, request),beforeRetry(state)andbeforeError(error)are not being unified into a single state-object signature. Matching ky's conventions is deliberate, and a hook that throws propagates that error as-is (never wrapped) to abort the request.beforeErroronly ever seesValifetchErrors. - Entry-point rule.
valifetch(.) is the core runtime plus core types;valifetch/typesis the superset of every public type;./error,./authand./mockare runtime subpaths. JSR publishes.,./authand./mock(disjoint symbol sets);./errorand./typesare npm-only because they only re-export symbols already in.,./author./mock. options(url, requestOptions). The HTTP-verb method is deliberately namedoptions(matching the OPTIONS HTTP verb); its parameter is internally namedrequestOptionsto avoid colliding with the method name.- Retry counters use different bases on purpose.
RetryOptions.delay(attempt)is 0-based (delay(0)computes the first retry's delay).BeforeRetryState.retryCountand theattemptfield on aDebugEventof type'retry'are both 1-based: they describe "the retry about to be performed", which reads more naturally in hook and log code than a 0-based count would.
See also Versioning and stability.