Skip to content

feat!: migrate from axios to fetch (v8)#2591

Open
WilliamBergamin wants to merge 32 commits intov8from
mirgate-from-axios-to-fetch
Open

feat!: migrate from axios to fetch (v8)#2591
WilliamBergamin wants to merge 32 commits intov8from
mirgate-from-axios-to-fetch

Conversation

@WilliamBergamin
Copy link
Copy Markdown
Contributor

@WilliamBergamin WilliamBergamin commented May 7, 2026

Summary

These changes migrates this project axios to the native Fetch API — a major step toward v8.

What changed

  • @slack/web-api — Removed axios, form-data, is-electron, and is-stream. HTTP requests now use globalThis.fetch (or a user-supplied fetch function). The public API surface is simpler: a single fetch option replaces agent, tls, requestInterceptor, and adapter.
  • @slack/webhook — Same migration: axios removed, replaced with native fetch.
  • @slack/socket-mode — Replaced the ws WebSocket library with undici's spec-compliant WHATWG WebSocket. A new dispatcher option enables proxy and custom TLS configuration. undici is declared as a peer dependency.

Breaking changes

Removed option Replacement
agent (http/https Agent) fetch option with a custom dispatcher
tls (pfx, cert, ca, etc.) fetch option with custom TLS config
requestInterceptor Wrap the fetch function
adapter Supply a custom fetch
attachOriginalToWebAPIRequestError Always attached now
httpAgent (socket-mode) dispatcher option (undici Dispatcher)
  • WebAPIHTTPError.headers type changed from IncomingHttpHeaders to Record<string, string>
  • Minimum Node.js version 20

Proxy configuration examples

Web API — proxy via custom fetch

const { ProxyAgent, fetch: undiciFetch } = require('undici');
const { WebClient } = require('@slack/web-api');

const dispatcher = new ProxyAgent('http://my-proxy:8080');

const client = new WebClient(process.env.SLACK_BOT_TOKEN, {
  fetch: (url, init) => undiciFetch(url, { ...init, dispatcher }),
});

Socket Mode — proxy via dispatcher

const { SocketModeClient, LogLevel } = require('@slack/socket-mode');
const { ProxyAgent } = require('undici');

const dispatcher = new ProxyAgent('http://my-proxy:8080');

const socketModeClient = new SocketModeClient({
  appToken: process.env.SLACK_APP_TOKEN,
  logLevel: LogLevel.DEBUG,
  // dispatcher is used for BOTH the WebSocket connection
  // AND the HTTP API calls (unless clientOptions.fetch is set)
  dispatcher,
});

Socket Mode — separate proxy for HTTP vs WebSocket

const { SocketModeClient } = require('@slack/socket-mode');
const { ProxyAgent, fetch: undiciFetch } = require('undici');

const wsProxy = new ProxyAgent('http://ws-proxy:8080');
const httpProxy = new ProxyAgent('http://http-proxy:9090');

const socketModeClient = new SocketModeClient({
  appToken: process.env.SLACK_APP_TOKEN,
  // WebSocket connections use this dispatcher
  dispatcher: wsProxy,
  clientOptions: {
    // HTTP API calls use this separate fetch
    fetch: (url, init) => undiciFetch(url, { ...init, dispatcher: httpProxy }),
  },
});

Webhook — proxy via custom fetch

const { IncomingWebhook } = require('@slack/webhook');
const { ProxyAgent, fetch: undiciFetch } = require('undici');

const dispatcher = new ProxyAgent('http://my-proxy:8080');

const webhook = new IncomingWebhook(process.env.SLACK_WEBHOOK_URL, {
  fetch: (url, init) => undiciFetch(url, { ...init, dispatcher }),
});

Custom fetch — override for testing or instrumentation

const { WebClient } = require('@slack/web-api');

const client = new WebClient(process.env.SLACK_BOT_TOKEN, {
  fetch: async (url, init) => {
    console.log(`→ ${init?.method ?? 'GET'} ${url}`);
    const start = Date.now();
    const response = await globalThis.fetch(url, init);
    console.log(`← ${response.status} (${Date.now() - start}ms)`);
    return response;
  },
});

Testing

Requirements

@WilliamBergamin WilliamBergamin self-assigned this May 7, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 7, 2026

⚠️ No Changeset found

Latest commit: e3bf6ed

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 84.00000% with 64 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (v8@edadd31). Learn more about missing BASE report.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@          Coverage Diff          @@
##             v8    #2591   +/-   ##
=====================================
  Coverage      ?   87.20%           
=====================================
  Files         ?       62           
  Lines         ?    10261           
  Branches      ?      417           
=====================================
  Hits          ?     8948           
  Misses        ?     1288           
  Partials      ?       25           
Flag Coverage Δ
cli-hooks 87.20% <84.00%> (?)
cli-test 87.20% <84.00%> (?)
logger 87.20% <84.00%> (?)
oauth 87.20% <84.00%> (?)
socket-mode 87.20% <84.00%> (?)
web-api 87.20% <84.00%> (?)
webhook 87.20% <84.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@WilliamBergamin WilliamBergamin changed the title feat: migrate from axios to fetch feat!: migrate from axios to fetch (v8) May 8, 2026
@WilliamBergamin WilliamBergamin marked this pull request as ready for review May 8, 2026 20:14
@WilliamBergamin WilliamBergamin requested a review from a team as a code owner May 8, 2026 20:14
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.

1 participant