react-dymo icon indicating copy to clipboard operation
react-dymo copied to clipboard

feat: Replace axios with native fetch API

Open TNAJanssen opened this issue 3 months ago • 1 comments

Summary

This PR migrates the codebase from axios to the native fetch API, removing the external dependency while maintaining all existing functionality.

Changes Made

🔧 Core Migration

  • Removed axios dependency from package.json
  • Created fetch wrapper (src/fetchUtils.js) with:
    • Custom error handling with FetchError class
    • isAbortError() helper for cancellation detection
    • Response interceptor pattern for retry logic
    • Automatic content-type handling

🔄 Request Cancellation

  • Replaced axios.CancelToken with native AbortController
  • Updated all React hooks to use AbortController for cleanup
  • Maintains proper request cancellation on component unmount

🔁 Retry Logic

  • Preserved automatic retry behavior for Dymo service discovery
  • Continues scanning ports 41951-41953 on both 127.0.0.1 and localhost
  • Maintains localStorage caching of successful connection parameters
  • Skips retry on HTTP 500 errors and aborted requests (same as before)

📝 Additional Fixes

  • Fixed missing moment.js import in storage.js by removing unused expiration logic (separate commit)

Testing

  • ✅ Build passes without errors
  • ✅ ESLint passes without warnings
  • ✅ All existing APIs maintain the same interface
  • ⚠️ Manual testing with Dymo hardware recommended

Breaking Changes

None - the API remains identical for consumers of this library.

Browser Compatibility

The fetch API and AbortController are well-supported in modern browsers. For older browser support, polyfills may be needed.

TNAJanssen avatar Jul 31 '25 08:07 TNAJanssen

Hi @TNAJanssen , thx for the contribution, I'll try to review the PR ASAP.

apenab avatar Aug 05 '25 09:08 apenab