Axios - promise-based HTTP client for browser and Node.js USE WHEN: user mentions "Axios", "HTTP requests", "API calls", "interceptors", "Axios instance", asks about "how to make HTTP calls", "configure Axios", "add auth header", "handle HTTP errors" DO NOT USE FOR: Fetch API - use `http-clients` instead; ky/ofetch - use `http-clients` instead; GraphQL clients - use `graphql-codegen` instead; tRPC - use `trpc` instead

GitHub
安装命令
npx skhub add claude-dev-suite/axios
Markdown
SKILL.md

Axios - Quick Reference

When to Use This Skill

  • HTTP requests in JavaScript/TypeScript applications
  • Configuring interceptors for auth/error handling
  • Creating Axios instances for specific APIs
  • Request/response transformation
  • File uploads and downloads

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: axios for comprehensive documentation.

Setup Base

npm install axios

Pattern Essenziali

GET Request

import axios from 'axios';

const response = await axios.get('/api/users');
const users = response.data;

// With params
const response = await axios.get('/api/users', {
  params: { page: 1, limit: 10 }
});

POST Request

const response = await axios.post('/api/users', {
  name: 'John',
  email: 'john@example.com'
});

Axios Instance

const api = axios.create({
  baseURL: 'https://api.example.com',
  timeout: 10000,
  headers: { 'Content-Type': 'application/json' }
});

// Use instance
const users = await api.get('/users');

Interceptors

// Request interceptor (add auth token)
api.interceptors.request.use(
  (config) => {
    const token = localStorage.getItem('token');
    if (token) {
      config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
  },
  (error) => Promise.reject(error)
);

// Response interceptor (handle errors)
api.interceptors.response.use(
  (response) => response,
  (error) => {
    if (error.response?.status === 401) {
      // Handle unauthorized
      window.location.href = '/login';
    }
    return Promise.reject(error);
  }
);

TypeScript Types

interface User {
  id: number;
  name: string;
  email: string;
}

const response = await api.get<User[]>('/users');
const users: User[] = response.data;

Error Handling

try {
  const response = await api.get('/users');
} catch (error) {
  if (axios.isAxiosError(error)) {
    console.error('API Error:', error.response?.data);
    console.error('Status:', error.response?.status);
  }
}

When NOT to Use This Skill

  • Native Fetch API patterns (use http-clients skill)
  • ky or ofetch configuration (use http-clients skill)
  • GraphQL client setup (use graphql-codegen skill)
  • tRPC client configuration (use trpc skill)
  • WebSocket connections

Anti-Patterns

Anti-PatternWhy It's BadSolution
No timeout configuredRequests hang indefinitelySet timeout in axios.create()
Hardcoded base URLsEnvironment couplingUse env variables for baseURL
No error interceptorInconsistent error handlingAdd response error interceptor
Not typing responsesLoses type safetyUse generics: axios.get<User>()
Duplicating auth logicMaintenance burdenUse request interceptor
Ignoring response statusSilent failuresCheck response.status or use validateStatus
No request cancellationMemory leaks on unmountUse AbortController
Logging sensitive dataSecurity riskRedact tokens/passwords from logs

Quick Troubleshooting

IssuePossible CauseSolution
CORS errorsServer not allowing originConfigure CORS on server, check preflight
401 UnauthorizedMissing or invalid tokenCheck interceptor, verify token
Network ErrorServer unreachable, CORSCheck baseURL, server status, CORS config
Timeout errorsRequest taking too longIncrease timeout or optimize endpoint
Request canceledAbortController triggeredCheck component lifecycle, don't cancel needed requests
Type errorsResponse shape mismatchVerify API response matches type definition
Interceptor not firingInterceptor added after requestAdd interceptors during client setup
Memory leaksNot canceling requests on unmountUse cleanup in useEffect
发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.24

发布时间

Sep 24, 2026

分类

未分类

许可证

MIT

源路径

skills/api-integration/axios

默认分支

main

最新提交

9496306

Tree SHA

fe4e2f1