mcpField
A
axios

axios

github.com/claude-dev-suiteDevelopment4679 installsUpdated 2d ago
Repository

About axios

A quick-reference skill for using Axios in JavaScript and TypeScript applications. It covers common request patterns and configuration practices, including interceptors, typed responses, and error handling.

Key features

  1. 01GET and POST request examples
  2. 02Axios instance configuration
  3. 03Request and response interceptors
  4. 04TypeScript response typing
  5. 05Error handling and troubleshooting

Use cases

  1. 01Making API requests in JavaScript or TypeScript
  2. 02Adding authentication and error-handling interceptors
  3. 03Configuring a client for a specific API
  4. 04Uploading or downloading files

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/claude-dev-suite/claude-dev-suite --skill axios

After installing, type/axiosin Claude Code to confirm it loaded.

Details

From the project README

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: '[email protected]'
});
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

Comments

Markdown supported