Hook-Fetch ๐
Welcome to Hook-Fetch! A modern HTTP request library based on the native fetch API, providing clean syntax, rich features, and a powerful plugin system.
Featuresโ
- ๐ Modern Design - Based on native fetch API, supports Promise and async/await
- ๐ Plugin System - Powerful plugin architecture with custom extensions
- ๐ Streaming Support - Perfect support for SSE (Server-Sent Events) and streaming data
- ๐ฏ TypeScript Support - Complete type definitions and type inference
- ๐ Request Retry - Built-in request retry mechanism
- ๐ก๏ธ Error Handling - Comprehensive error handling and exception catching
- ๐จ Framework Integration - React and Vue Hook support
- ๐ฆ Lightweight - Small size with no extra dependencies
- ๐ง Highly Configurable - Flexible configuration options for various needs
Quick Startโ
Installationโ
# Using npm
npm install hook-fetch
# Using yarn
yarn add hook-fetch
# Using pnpm
pnpm add hook-fetch
Basic Usageโ
import hookFetch from 'hook-fetch';
// GET request
const response = await hookFetch('https://api.example.com/users').json();
console.log(response);
// POST request
const newUser = await hookFetch('https://api.example.com/users', {
method: 'POST',
data: { name: 'John', email: 'john@example.com' }
}).json();
Create Instanceโ
// Create a configured instance
const api = hookFetch.create({
baseURL: 'https://api.example.com',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your-token'
},
timeout: 5000
});
// Use the instance
const users = await api.get('/users').json();
Why Choose Hook-Fetch?โ
Advantages over other librariesโ
- vs Axios: More lightweight, based on modern fetch API, better TypeScript support
- vs Native fetch: Cleaner API, built-in error handling and retry mechanism
- vs Other fetch libraries: Unique plugin system and streaming support
Use Casesโ
- Modern web application development
- Scenarios requiring streaming data processing
- Projects sensitive to bundle size
- Highly customizable request processing needs
- Data fetching in React/Vue projects
Next Stepsโ
- Getting Started - Learn basic usage
- API Reference - View complete API documentation
- Plugin System - Learn how to use and develop plugins
- Framework Integration - React and Vue integration guide
- Best Practices - Recommended usage patterns and techniques
Community and Supportโ
Let's start exploring the powerful features of Hook-Fetch!