Skip to content

docs: Axios to @data-client/rest migration guide, codemod, and skill#3867

Merged
ntucker merged 32 commits intomasterfrom
cursor/axios-migration-8f90
Apr 4, 2026
Merged

docs: Axios to @data-client/rest migration guide, codemod, and skill#3867
ntucker merged 32 commits intomasterfrom
cursor/axios-migration-8f90

Conversation

@ntucker
Copy link
Copy Markdown
Collaborator

@ntucker ntucker commented Apr 4, 2026

Fixes # .

Motivation

Users migrating from axios to @data-client/rest need guidance on how to translate axios patterns (instances, interceptors, error handling, cancellation, etc.) into RestEndpoint lifecycle methods. This PR provides documentation, automated tooling, and AI-assisted migration support.

Solution

1. Documentation guide (docs/rest/guides/axios-migration.md)

  • AI skill install (SkillTabs) at the top for easy access — preferred migration path
  • Leads with type-safe path parameters as the primary migration benefit
  • Quick reference table mapping every axios config option to its RestEndpoint equivalent
  • Interactive EndpointPlayground examples for GET, POST, and instance creation
  • Before/after tabs for interceptors, error handling, and cancellation
  • Codemod section references the skill as preferred approach for AI users
  • Added to REST sidebar after Django Integration

2. jscodeshift codemod (website/static/codemods/axios-to-rest.js)

  • Replaces import axios from 'axios' with import { RestEndpoint } from '@data-client/rest'
  • Converts axios.create({ baseURL, headers }) into RestEndpoint subclasses with urlPrefix + getHeaders()
  • Transforms axios.get() / .post() / .put() / .patch() / .delete() calls into new RestEndpoint({ path, method })
  • Handles aliased imports, multiple create calls, type import removal
  • Preserves unknown named imports from axios (e.g. isAxiosError, spread) while removing known type-only imports
  • Keeps axios imported whenever unresolved usages remain (e.g. dynamic URL calls), while still injecting RestEndpoint when partial conversion occurred
  • Handles TypeScript: import type, inline type specifiers, generic type parameters on calls
  • Handles template literal URLs: axios.get(`/users/${id}`)
  • Skips calls with config objects as second arg (not deterministically transformable)
  • Follow-up fix: preserves CancelToken and AxiosError named imports when used as runtime values (CancelToken.source(), instanceof AxiosError) even if default axios import is removed
  • Follow-up fix: resolves instance call targets by lexical binding scope, preventing shadowed variables (e.g. nested const api = createOtherClient()) from being incorrectly rewritten to generated endpoint classes

3. Codemod tests (website/static/codemods/__tests__/axios-to-rest.test.js) — expanded coverage for:

  • Import rewriting (default, aliased, type-only, mixed named/type, unknown named)
  • Runtime value import preservation (CancelToken and AxiosError)
  • axios.create() (baseURL, headers, spreads, aliased, multiple, empty, exported)
  • Direct calls (all HTTP methods, template literals, non-literal URLs, config objects)
  • Instance method calls after create transform
  • Shadowed-scope regression: nested identifiers with the same name are no longer rewritten
  • TypeScript edge cases (import type, inline type specifiers, generics, typeof axios)
  • Real-world patterns (chained .then(), await destructuring, axios() direct call, axios.all, conditionals)

4. Migration skill (.cursor/skills/axios-to-rest-migration/SKILL.md)

  • Referenced from the doc guide via SkillTabs and skills.sh link
  • Runs the codemod as Step 1
  • Documents all non-deterministic migration patterns the codemod cannot handle:
    • Interceptors → getHeaders() / getRequestInit() / parseResponse() / process()
    • Error handling → NetworkError
    • timeout, cancelToken, responseType, paramsSerializer, auth, validateStatus, XSRF, upload progress
  • Includes search patterns for finding axios usage in a codebase

Open questions

  • Should the codemod also handle require('axios') (CJS) in addition to ESM imports?
  • Should the doc guide include a HooksPlayground example showing the full flow from axios call to useSuspense hook?
Open in Web Open in Cursor 

cursoragent and others added 5 commits April 4, 2026 14:37
Co-authored-by: natmaster <natmaster@gmail.com>
Co-authored-by: natmaster <natmaster@gmail.com>
Co-authored-by: natmaster <natmaster@gmail.com>
Co-authored-by: natmaster <natmaster@gmail.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 4, 2026

⚠️ No Changeset found

Latest commit: 5a52953

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs-site Ignored Ignored Preview Apr 4, 2026 8:20pm

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.08%. Comparing base (53c7091) to head (5a52953).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3867   +/-   ##
=======================================
  Coverage   98.08%   98.08%           
=======================================
  Files         152      152           
  Lines        2876     2876           
  Branches      564      564           
=======================================
  Hits         2821     2821           
  Misses         11       11           
  Partials       44       44           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ntucker ntucker marked this pull request as ready for review April 4, 2026 15:00
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 4, 2026

Deployment failed with the following error:

The `vercel.json` schema validation failed with the following message: `ignoreCommand` should NOT be longer than 256 characters

Learn More: https://vercel.com/docs/concepts/projects/project-configuration

…only

PR branches now diff against merge-base with master so that website/
and docs/ changes in any commit trigger a preview deploy, not just
changes in the tip commit.

Co-authored-by: natmaster <natmaster@gmail.com>
cursoragent and others added 2 commits April 4, 2026 15:31
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
… failure

The previous ignoreCommand used 'git fetch origin' which fails on Vercel
PR builds because the 'origin' remote doesn't exist. Simplified to:
- gh-pages* branches: always skip (exit 0)
- master branch: diff HEAD^ HEAD for ./ and ../docs/ (squash merges)
- PR branches: always build (exit 1) — avoids the remote issue entirely

Co-authored-by: natmaster <natmaster@gmail.com>
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
cursoragent and others added 2 commits April 4, 2026 15:51
- Remove import type declarations from 'axios' entirely
- Filter out inline type specifiers (import { type X })
- Only add RestEndpoint import when a default import existed
- Avoid adding RestEndpoint for type-only imports with no default

Co-authored-by: natmaster <natmaster@gmail.com>
Cover 13 new scenarios:
- Generic type parameters on axios method calls
- as casts with AxiosResponse
- import type declarations (with/without default import)
- Inline type specifiers (import { type X })
- Inline type + unknown named imports
- typeof axios as type annotation (alone and with method calls)
- Re-exports from 'axios'
- declare module augmentations
- Multiple import statements from 'axios'
- Multiple imports with type references as annotations

Co-authored-by: natmaster <natmaster@gmail.com>
Tests added for 10 real-world axios usage patterns:
1. Chained .then() - preserved after transform
2. await with destructured result - transforms correctly
3. axios() as default function call - left unchanged (no-op)
4. Config object as second arg - left unchanged (no-op, was previously silently dropped)
5. axios.request() - left unchanged (no-op)
6. Template literals in URL - now transformed (was previously skipped)
7. Exported axios.create() instances - produces exported class
8. axios.create() with no arguments - produces empty class
9. Nested/conditional axios calls - all branches transformed
10. axios.all/axios.spread - inner gets transformed, axios.all preserved

Codemod fixes:
- Skip transform when a config object is passed as second argument
  (previously the config was silently dropped, producing broken output)
- Support template literal URLs in addition to string literals
  (previously template literals caused the call to be silently skipped)
- Return source unchanged (instead of undefined) when no axios import found

Co-authored-by: natmaster <natmaster@gmail.com>
cursoragent and others added 2 commits April 4, 2026 17:27
- SkillTabs component with link to skills.sh
- Skill positioned before 'Why migrate' for easy access
- Codemod section references skill as preferred approach

Co-authored-by: natmaster <natmaster@gmail.com>
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
cursoragent and others added 2 commits April 4, 2026 17:42
- New 'Migration Guides' category in left nav between Data Guides and Endpoint API
- Add brief migration section to REST Usage page with SkillTabs + link to full guide

Co-authored-by: natmaster <natmaster@gmail.com>
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
ntucker and others added 2 commits April 4, 2026 13:52
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6906b2e. Configure here.

Move axios-to-rest-migration from standalone skill into a reference
file under data-client-rest-setup. Add migration references for raw
fetch, ky, superagent, and got. SKILL.md now handles detection and
routes to the relevant reference — agent only loads what it needs.

Update SkillTabs to support multiple skills, update docs to reference
data-client-rest-setup as the single migration entry point.

Made-with: Cursor
ntucker and others added 3 commits April 4, 2026 14:43
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
Co-authored-by: Nathaniel Tucker <me@ntucker.me>
@ntucker ntucker merged commit 6027f83 into master Apr 4, 2026
23 checks passed
@ntucker ntucker deleted the cursor/axios-migration-8f90 branch April 4, 2026 20:30
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