Skip to content

refactor: migrate JavaScript SDK from Axios to Fetch API#221

Open
elevatebart wants to merge 5 commits intomainfrom
claude/replace-axios-with-fetch-8KMHC
Open

refactor: migrate JavaScript SDK from Axios to Fetch API#221
elevatebart wants to merge 5 commits intomainfrom
claude/replace-axios-with-fetch-8KMHC

Conversation

@elevatebart
Copy link
Copy Markdown
Contributor

What changes are being made and why?

This PR migrates the JavaScript SDK from Axios to the native Fetch API, removing the axios dependency and updating the HTTP client implementation accordingly.

Key changes:

  • Removed all Axios-specific code (configureAxios, Axios interceptors, AxiosInstance types)
  • Replaced configureAxios() with configureFetch() that uses the Fetch API
  • Updated configureClient() to work with the hey-api Fetch client instead of creating an Axios instance
  • Migrated request/response interceptors to use Fetch API patterns:
    • Request interceptors now work with Request objects
    • Response interceptors now work with Response objects
    • Error handling updated to use the Fetch client's error interceptor API
  • Implemented download progress tracking via ReadableStream instead of Axios progress events
  • Updated token refresh logic to use native fetch() instead of Axios instance methods
  • Changed useClient() to return a FetchClient type instead of AxiosInstance
  • Updated OpenAPI code generation config to use @hey-api/client-fetch instead of @hey-api/client-axios
  • Updated test setup to use Fetch API interceptor patterns
  • Removed axios from package.json dependencies

The migration maintains feature parity with the previous Axios implementation, including:

  • Request/response progress tracking with NProgress
  • Token refresh queue handling for 401 responses
  • Router integration for authentication timeouts
  • Error message handling via coreStore
  • Empty multipart body handling
  • Content-Type header management for body-less requests

How the changes have been QAed?

The changes maintain backward compatibility at the API level (same configureFetch() options and behavior). The migration is internal to the HTTP client implementation. Existing tests have been updated to work with the Fetch API interceptor patterns.

https://claude.ai/code/session_01DN2sot7zsZKFBm1duuUURo

claude and others added 5 commits April 29, 2026 15:54
Removes the axios runtime dependency to shrink the published package and
align with the native Fetch API available in all modern environments.

Breaking changes:
- configureAxios() renamed to configureFetch(); returns FetchClient instead of AxiosInstance
- useClient() now returns FetchClient
- Config key baseURL → baseUrl (hey-api/client-fetch convention)
- Request interceptors receive Request; response interceptors receive Response
- Upload progress dropped (Fetch API limitation); download progress preserved via ReadableStream
- Error interceptors use client.interceptors.error.use() (separate from response)

https://claude.ai/code/session_01DN2sot7zsZKFBm1duuUURo
…dies

@hey-api/client-fetch spreads jsonBodySerializer as the global default,
which JSON.stringify's every body — including YAML strings — before sending.
This caused createFlow (application/x-yaml) to send the YAML wrapped in
JSON quotes, which the Kestra YAML parser correctly rejected.

The fix: replace the default with a type-aware serializer that passes strings
and FormData/URLSearchParams through unchanged, and only calls JSON.stringify
on plain objects and arrays.

Also updates basicSDKUsageExample.ts to use configureClient (which carries
the smart serializer) instead of raw client.setConfig.

https://claude.ai/code/session_01DN2sot7zsZKFBm1duuUURo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants