How Axios Handles HTTP/2 and HTTP/3 Requests

Axios handles HTTP/2 and HTTP/3 network requests differently depending on its runtime environment: the browser or Node.js. In web browsers, Axios delegates network operations to the browser's underlying engine, which automatically supports HTTP/2 and HTTP/3 transparently. In Node.js, Axios relies on native core modules that default strictly to HTTP/1.1, requiring third-party adapters or custom transport layers to enable HTTP/2, while native HTTP/3 support remains currently unavailable.

Axios in the Browser

When running inside a browser environment, Axios uses the XMLHttpRequest interface (or the fetch API if configured with a custom adapter).

From the developer's perspective in the browser, Axios code remains identical regardless of whether the underlying connection is HTTP/1.1, HTTP/2, or HTTP/3.

Axios in Node.js

In a Node.js environment, Axios behaves differently because it directly interfaces with Node's low-level networking APIs.

Enabling HTTP/2 Support in Node.js

To process HTTP/2 requests using Axios in Node.js, you must bypass the default HTTP/1.1 adapter and implement an HTTP/2-compatible transport layer.

  1. Custom Adapters: You can supply a custom adapter to Axios using packages like http2-wrapper or Node’s native http2 module.
  2. Agent Compatibility: Because standard http.Agent instances are incompatible with HTTP/2 sessions, the custom transport must manage HTTP/2 session lifecycles, stream multiplexing, and fallback mechanisms for servers that only support HTTP/1.1.

The Status of HTTP/3 (QUIC) in Axios

HTTP/3 relies on the QUIC transport protocol over UDP instead of TCP.