Get up and running with hyperwiz in minutes. Follow this step-by-step guide to create your first HTTP client.
npm install hyperwiz
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' }
);
Install the package
Import and create client
Make HTTP requests
Follow these steps to get started with hyperwiz
npm install hyperwiz
yarn add hyperwiz
import { createClient } from 'hyperwiz';
// Create a simple client
const api = createClient('https://api.example.com');
// That's it! You're ready to make requests.
The base URL is the foundation of your API client. All requests will be made relative to this URL.
// 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);
}
You've successfully created your first hyperwiz client and made HTTP requests! All responses follow a consistent format.
Customize your client with powerful configuration options
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
});
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
});
Learn common patterns and best practices
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');
// 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');
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
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
});
}
Start building with hyperwiz today and experience the power of simple, flexible HTTP requests.