Quick Start Guide

Get up and running with hyperwiz in minutes. Follow this step-by-step guide to create your first HTTP client.

Quick Start in 30 seconds

1
Install the package
Install
npm install hyperwiz
2
Start using it
TypeScript
import { createClient } from 'hyperwiz';

const api = createClient(
  'https://api.example.com', 
  { 
    logging: true, 
    retry: true,
    cache: true 
  }
);

const users = await api.get('/users');
const newUser = await api.post(
  '/users', 
  { name: 'John' }
);

Step 1: Install

Install the package

Step 2: Import

Import and create client

Step 3: Use

Make HTTP requests

Step-by-Step Guide

Follow these steps to get started with hyperwiz

1

Install hyperwiz

Using npm

Terminal
npm install hyperwiz

Using yarn

Terminal
yarn add hyperwiz
2

Create your first client

TypeScript
import { createClient } from 'hyperwiz';

// Create a simple client
const api = createClient('https://api.example.com');

// That's it! You're ready to make requests.

💡 Tip

The base URL is the foundation of your API client. All requests will be made relative to this URL.

3

Make your first request

TypeScript
// GET request
const users = await api.get('/users');

// POST request
const newUser = await api.post('/users', { 
  name: 'John Doe', 
  email: 'john@example.com' 
});

// Handle responses
if (users.success) {
  console.log('Users:', users.data);
} else {
  console.error('Error:', users.error);
}

✅ Success!

You've successfully created your first hyperwiz client and made HTTP requests! All responses follow a consistent format.

Add Configuration

Customize your client with powerful configuration options

Basic Configuration

TypeScript
const api = createClient('https://api.example.com', {
  logging: true,           // Enable request/response logging
  retry: true,             // Auto retry failed requests
  cache: true,             // Enable smart caching
  timeout: 10000,          // 10 second timeout
  credentials: 'include'   // Include cookies
});

Advanced Configuration

TypeScript
const api = createClient('https://api.example.com', {
  retry: {
    maxRetries: 3,           // Retry up to 3 times
    retryDelay: 1000,        // Start with 1 second delay
    maxDelay: 10000,         // Maximum 10 second delay
    backoffMultiplier: 2,    // Double the delay each retry
    retryOnStatus: [408, 429, 500, 502, 503, 504], // Retry on these status codes
    retryOnNetworkError: true // Retry on network errors
  },
  cache: {
    enabled: true,
    maxAge: 5 * 60 * 1000,  // Cache for 5 minutes
    maxSize: 50,             // Maximum 50 cached items
    storage: 'indexeddb',    // Use IndexedDB for persistence
    includeQueryParams: true // Include query params in cache key
  },
  logging: true
});

Common Patterns

Learn common patterns and best practices

Adding Authentication

TypeScript
const api = createClient('https://api.example.com');

// Add token interceptor
api.addBefore((config, url) => {
  const token = localStorage.getItem('token');
  if (token) {
    return {
      ...config,
      headers: {
        ...config.headers,
        'Authorization': `Bearer ${token}`
      }
    };
  }
  return config;
});

// Now all requests automatically include the token
const profile = await api.get('/user/profile');

Error Handling

TypeScript
// Add error interceptor
api.addErrorHandler((error, url, requestConfig) => {
  console.error(`❌ Error for ${requestConfig?.method} ${url}:`, error);
  
  // Handle specific errors
  if (error.status === 401) {
    // Redirect to login
    window.location.href = '/login';
  }
  
  return error;
});

// All errors are automatically handled
const data = await api.get('/protected-data');

Smart Caching

TypeScript
const api = createClient('https://api.example.com', {
  cache: {
    enabled: true,
    maxAge: 5 * 60 * 1000,  // Cache for 5 minutes
    storage: 'indexeddb',    // Use IndexedDB for persistence
    includeQueryParams: true // Include query params in cache key
  }
});

// First request: fetches from server
const users1 = await api.get('/users'); // ⏳ Network request

// Second request: served from cache (instant)
const users2 = await api.get('/users'); // 💾 Cache hit (instant)

// Cache automatically expires after maxAge
// Cache automatically evicts old entries when maxSize is reached

TypeScript Support

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

const api = createClient('https://api.example.com');

// TypeScript knows the response type
const users = await api.get<User[]>('/users');
if (users.success) {
  users.data.forEach(user => {
    console.log(user.name); // TypeScript autocomplete works
  });
}

Ready to build?

Start building with hyperwiz today and experience the power of simple, flexible HTTP requests.