Skip to content

Repository files navigation

@neabyte/fetch

HTTP client with timeout, retries, streaming, downloads, and error handling for browser and Node.js.

TypeScriptnpm versionLicense: Apache 2.0Bundle SizeNode.js

ChromeFirefoxSafariOperaEdge
Latest ✔Latest ✔Latest ✔Latest ✔Latest ✔

✨ Features

  • 🌐 Universal Support - Browser and Node.js
  • 🔐 Authentication - Basic, Bearer, and API key authentication
  • 🔒 SSL Pinning - Certificate validation with SHA-256 pinning
  • 🍪 Cookie Management - Automatic cookie handling for browser and Node.js
  • Request Cancellation - AbortSignal support
  • ⏱️ Timeout Control - Configurable timeouts (default: 30s)
  • 🔄 Retry Logic - Exponential backoff with Retry-After header support
  • 📡 NDJSON Streaming - Real-time JSON processing
  • 📊 Progress Tracking - Upload and download progress
  • 🚦 Rate Limiting - Control transfer speeds with maxRate option
  • 📦 Request Bodies - JSON, FormData, URLSearchParams, binary data
  • 📥 File Downloads - Cross-platform file downloads
  • ⚖️ Request Balancer - Load balance requests across multiple endpoints
  • 📨 Response Forwarder - Forward responses to multiple endpoints
  • 🛡️ Error Handling - Detailed error information with status codes

📦 Installation

NPM

npm install @neabyte/fetch

CDN (Browser)

<!-- ES Modules (Recommended) --><scripttype="module">importfetchfrom'https://cdn.jsdelivr.net/npm/@neabyte/fetch/+esm'// orimportfetchfrom'https://esm.sh/@neabyte/fetch'// orimportfetchfrom'https://esm.run/@neabyte/fetch'// Use fetch as normalconstdata=awaitfetch.get('https://api.example.com/data')</script><!-- UMD (Global Variable) --><scriptsrc="https://unpkg.com/@neabyte/fetch@latest/dist/index.umd.min.js"></script><script>// Available as global variable 'Fetch' with default exportconstFetchClient=window.Fetch.defaultconstdata=awaitFetchClient.get('https://api.example.com/data')</script>

📖 Quick Start

importfetch,{FetchError}from'@neabyte/fetch'// Simple GET requestconstusers=awaitfetch.get('https://jsonplaceholder.typicode.com/users')// POST with JSON bodyconstnewPost=awaitfetch.post('https://jsonplaceholder.typicode.com/posts',{title: 'My New Post',body: 'This is the content',userId: 1})// Error handlingtry{constdata=awaitfetch.get('https://api.example.com/data')}catch(error){if(errorinstanceofFetchError){console.log('HTTP Error:',error.status,error.message)}}// Rate limiting for downloads (100KB/s)constfile=awaitfetch.get('https://example.com/large-file.zip',{download: true,filename: 'large-file.zip',maxRate: 100*1024,// 100KB/sonProgress: (percentage)=>console.log(`Download: ${percentage}%`)})// Rate limiting for uploads (50KB/s)constresult=awaitfetch.post('https://api.example.com/upload',fileData,{maxRate: 50*1024,// 50KB/sonProgress: (percentage)=>console.log(`Upload: ${percentage}%`)})// Cookie management (automatic in browser, manual in Node.js)constresponse=awaitfetch.get('https://api.example.com/data',{withCookies: true// Enables cookie handling})

For detailed examples and usage patterns, see the documentation.


🗺️ Roadmap

🔮 Planned Features

  • HTTP Proxy Support - HTTP proxy connections
  • Proxy Authentication - Username/password for proxies
  • Request/Response Interceptors - Request and response modification
  • Request/Response Transformers - Data transformation
  • SOCKS Proxy Support - SOCKS4/SOCKS5 proxy connections

📋 Future Considerations

  • Additional proxy types and configurations
  • Enhanced proxy error handling
  • Proxy connection pooling

📄 License

This project is licensed under the Apache License 2.0. See the LICENSE file for more info.

About

🚧 HTTP client based on the Fetch API with timeout, retries, streaming, and downloads for browser and Node.js.

Topics

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages