Add ky HTTP client support#1802
Open
torrespro wants to merge 3 commits into
Open
Conversation
Introduces ky as a third supported HTTP client alongside Fetch and Axios.
The generated client is a drop-in for Fetch: same HttpResponse<D,E> wrapper,
query serialization, cancelToken, secure/securityWorker, format, unwrapResponseData,
and disableThrowOnError — backed by ky.create({ throwHttpErrors: false }).
Also fixes a CLI bug where any truthy --http-client value was coerced to
axios instead of being honored as the literal string.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 17be8d5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
6 issues found across 19 files
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
- Add timeout: false and retry: 0 to ky.create() — fetch has no built-in timeout or retry; disabling ky's defaults preserves parity - Move AbortController cleanup to .finally() so it runs on rejection too - Restore sta bin alias and fix tsdown.config.ts to emit both bin entries explicitly (bun add had dropped sta from the auto-generated bin field) - Use HttpClientType alias in types/index.ts instead of a hard-coded union - Update changeset to drop "drop-in match" claim and note retry/timeout defaults Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously any invalid value silently fell back to fetch. Now the CLI throws with a clear message listing the valid options. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PR #1601 added initial ky support but has been stale for a while and is now in a conflicting state. Its template implementation was also incomplete — it returned a
KyResponsetype instead of the project'sHttpResponse<D,E>wrapper, and dropped support forformat,unwrapResponseData,cancelToken,customFetch, anddisableThrowOnError.Separately, the
generatecommand had a latent bug where any truthy--http-clientvalue was silently coerced toaxiosrather than being used as the literal string.Solution
Redone from scratch with full feature parity against the Fetch client:
templates/base/http-clients/ky-http-client.ejs— new template backed byky.create({ fetch: customFetch ?? fetch, throwHttpErrors: false }). Preserves theHttpResponse<D,E>response wrapper,ResponseFormat, manual query serialization (not ky'ssearchParams),secure/securityWorker,cancelToken/AbortController,formatparsing,disableThrowOnError,unwrapResponseData, andbaseApiParams/mergeRequestParams. Drop-in compatible withprocedure-call.ejs.src/constants.ts— addedKY: "ky"toHTTP_CLIENT.types/index.ts— widened the hard-codedhttpClientTypeunion to include"ky".index.ts— fixed the--http-clientCLI resolution bug; the value is now validated againstObject.values(HTTP_CLIENT)and honored directly, with the legacy--axiosboolean as a fallback.templates/default/procedure-call.ejsandtemplates/modular/procedure-call.ejs— changed theFORM_DATAresponse-format predicate fromisFetchTemplate ?to!== HTTP_CLIENT.AXIOS ?so ky (like fetch) uses"formData"rather than"document".package.json— addedkyas a devDependency so generated output typechecks in CI.README.md— documented ky alongside Fetch and Axios..changeset/add-ky-http-client.md— minor version bump.Verification
Three new spec test dirs cover the ky client:
tests/spec/ky/(base),tests/spec/kySingleHttpClient/(--single-http-client), andtests/spec/jsKy/(--js/ JS translation), mirroring the existing axios test coverage.Closes #1601
Summary by cubic
Adds
kyas a first-class HTTP client with full Fetch parity and fixes--http-clienthandling so the chosen client is respected. Disablesky’s default retry/timeout for parity and restores thestaCLI alias.New Features
--http-client kyandhttpClientType: "ky"; generated client usesky.create({ fetch: customFetch ?? fetch, throwHttpErrors: false, timeout: false, retry: 0 })with the sameHttpResponse<D,E>/unwrapResponseDatabehavior as Fetch.secure/securityWorker,cancelToken(AbortController), manual query serialization,format,disableThrowOnError,customFetch, andbaseApiParamsmerge.axiosclients now use"formData"for form-data responses.ky; addedkyas a devDependency; added TS/JS and single-http-client tests forky.Bug Fixes
--http-client("fetch" | "axios" | "ky"); invalid values throw with a clear message; legacy--axiosstill works.stabin alias so bothstaandswagger-typescript-apiCLIs work.AbortControllercleanup runs on errors via.finally().Written for commit 17be8d5. Summary will update on new commits.