Claude Skills Guide

When building modern applications, HTTP requests are the backbone of data exchange. Whether you’re fetching from a REST API, sending form data, or handling authentication tokens, having a solid HTTP client workflow saves hours of debugging. This guide walks you through creating a practical Axios workflow that integrates smoothly with Claude Code.

Setting Up Your Axios Instance

The first step involves configuring a centralized Axios instance with sensible defaults. Rather than making ad-hoc requests throughout your codebase, create a dedicated HTTP client module:

// src/api/client.js
import axios from 'axios';

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

export default apiClient;

This approach allows you to modify global settings—such as base URL or default headers—in one place rather than hunting through dozens of files.

Request and Response Interceptors

Interceptors are powerful tools for handling cross-cutting concerns like authentication tokens and error logging. Add these to your client configuration:

// src/api/client.js (continued)
apiClient.interceptors.request.use(
  (config) => {
    const token = localStorage.getItem('authToken');
    if (token) {
      config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
  },
  (error) => Promise.reject(error)
);

apiClient.interceptors.response.use(
  (response) => response,
  (error) => {
    if (error.response?.status === 401) {
      // Handle token refresh or logout
      window.location.href = '/login';
    }
    return Promise.reject(error);
  }
);

This pattern ensures every request includes authentication automatically, while responses are normalized before reaching your components.

Building Service Modules

Organize your API calls into service modules grouped by feature or domain. For instance, a user service might look like:

// src/api/services/userService.js
import apiClient from '../client';

export const userService = {
  getProfile: () => apiClient.get('/users/me'),
  
  updateProfile: (data) => apiClient.put('/users/me', data),
  
  getOrders: (params) => apiClient.get('/users/me/orders', { params }),
  
  deleteAccount: () => apiClient.delete('/users/me'),
};

Service modules keep your components clean and make testing straightforward. When you need to swap the underlying HTTP library, only these service files require updates.

Handling Concurrent Requests

Modern applications often need to fetch multiple resources simultaneously. Axios provides Promise.all for parallel requests:

async function loadDashboardData() {
  const [user, orders, notifications] = await Promise.all([
    userService.getProfile(),
    userService.getOrders({ limit: 5 }),
    notificationService.getUnread(),
  ]);
  
  return { user: user.data, orders: orders.data, notifications: notifications.data };
}

This pattern reduces wait time significantly compared to sequential requests.

Error Handling Strategies

solid error handling distinguishes production-ready code from prototypes. Create a utility function that categorizes errors:

// src/api/utils/errorHandler.js
export function handleApiError(error) {
  if (error.response) {
    // Server responded with error status
    const { status, data } = error.response;
    switch (status) {
      case 400:
        return 'Invalid request data';
      case 403:
        return 'Access denied';
      case 404:
        return 'Resource not found';
      case 500:
        return 'Server error';
      default:
        return data.message || 'An error occurred';
    }
  } else if (error.request) {
    return 'Network error - please check your connection';
  }
  return 'Unexpected error';
}

Displaying user-friendly messages while logging detailed errors for debugging is essential for maintainability.

Integrating with Claude Code Skills

Your Axios workflow pairs excellently with Claude Code skills for enhanced productivity. When generating API documentation, the pdf skill helps create downloadable API guides. For frontend integration, the frontend-design skill provides component patterns that consume your service modules elegantly.

If you’re practicing test-driven development, the tdd skill assists in writing unit tests for your service functions before implementation. The supermemory skill stores API schemas and endpoint documentation, making future refactoring faster.

For example, when documenting your API contract:

/**
 * @typedef {Object} User
 * @property {string} id
 * @property {string} email
 * @property {string} name
 */

/**
 * Fetches current user profile
 * @returns {Promise<User>}
 */
export const getProfile = () => apiClient.get('/users/me');

This JSDoc format works well with documentation generation tools.

Testing Your HTTP Client

Writing tests for your Axios setup prevents regressions:

import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';

describe('userService', () => {
  let mock;
  
  beforeEach(() => {
    mock = new MockAdapter(axios);
  });
  
  afterEach(() => {
    mock.restore();
  });
  
  it('fetches user profile successfully', async () => {
    const mockUser = { id: '1', email: 'test@example.com', name: 'Test User' };
    mock.onGet('/users/me').reply(200, mockUser);
    
    const response = await userService.getProfile();
    expect(response.data).toEqual(mockUser);
  });
});

Performance Optimization Tips

Consider implementing request caching for frequently accessed data:

const cache = new Map();

apiClient.interceptors.response.use((response) => {
  const cacheKey = response.config.url + JSON.stringify(response.config.params);
  if (response.config.method === 'get') {
    cache.set(cacheKey, { data: response.data, timestamp: Date.now() });
  }
  return response;
});

For large file downloads or uploads, Axios supports progress events:

apiClient.post('/upload', formData, {
  onUploadProgress: (progressEvent) => {
    const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
    console.log(`Upload progress: ${percentCompleted}%`);
  },
});

Summary

A well-structured Axios HTTP client workflow transforms raw API calls into maintainable, testable code. Centralize your configuration, use interceptors wisely, organize services by domain, and implement thorough error handling. This foundation scales with your application while keeping development velocity high.

Pair this workflow with Claude Code skills like pdf for documentation, frontend-design for UI components, and tdd for comprehensive test coverage. Your API integration becomes not just functional, but professional-grade.

Built by theluckystrike — More at zovo.one