axios-h2-adapter
v1.0.4
Published
An Axios adapter that enables HTTP/2 requests with automatic fallback to HTTP/1.1. Seamlessly integrates with existing Axios instances for improved performance and modern protocol support.
Readme
axios-http2-adapter
An HTTP/2-capable adapter for Axios, providing automatic fallback to HTTP/1.1 when HTTP/2 is unsupported or unavailable.
✨ Features
- Uses the HTTP/2 protocol for supported HTTPS endpoints
- Automatically falls back to HTTP/1.1 (over HTTPS or HTTP) when needed
- Seamlessly integrates with existing
axiosinstances - Compatible with both browser-like and Node.js environments
📦 Installation
npm install axios-h2-adapter🚀 Usage
import axios from "axios";
import adapter from "axios-h2-adapter";
const axiosInstance = axios.create({
adapter,
});
const res = await axiosInstance.get("https://example.com");
console.log(res.status); // 200You can also pass adapter inline:
const res = await axios.get("https://example.com", {
adapter,
});🔍 Fallback Behavior
If the server supports HTTP/2, requests will use it automatically.
If HTTP/2 is not supported, it will gracefully fall back to HTTP/1.1.
Works for both HTTPS and HTTP requests (though HTTP/2 only applies to HTTPS).
✅ Tests
To run tests:
npm install
npm test