Skip to content

NeaByteLab/Fetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

29 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

@neabyte/fetch

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

TypeScript npm version License: Apache 2.0 Bundle Size Node.js

Chrome Firefox Safari Opera Edge
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) -->
<script type="module">
  import fetch from 'https://cdn.jsdelivr.net/npm/@neabyte/fetch/+esm'
  // or
  import fetch from 'https://esm.sh/@neabyte/fetch'
  // or
  import fetch from 'https://esm.run/@neabyte/fetch'

  // Use fetch as normal
  const data = await fetch.get('https://api.example.com/data')
</script>

<!-- UMD (Global Variable) -->
<script src="https://unpkg.com/@neabyte/fetch@latest/dist/index.umd.min.js"></script>
<script>
  // Available as global variable 'Fetch' with default export
  const FetchClient = window.Fetch.default
  const data = await FetchClient.get('https://api.example.com/data')
</script>

๐Ÿ“– Quick Start

import fetch, { FetchError } from '@neabyte/fetch'

// Simple GET request
const users = await fetch.get('https://jsonplaceholder.typicode.com/users')

// POST with JSON body
const newPost = await fetch.post('https://jsonplaceholder.typicode.com/posts', {
  title: 'My New Post',
  body: 'This is the content',
  userId: 1
})

// Error handling
try {
  const data = await fetch.get('https://api.example.com/data')
} catch (error) {
  if (error instanceof FetchError) {
    console.log('HTTP Error:', error.status, error.message)
  }
}

// Rate limiting for downloads (100KB/s)
const file = await fetch.get('https://example.com/large-file.zip', {
  download: true,
  filename: 'large-file.zip',
  maxRate: 100 * 1024, // 100KB/s
  onProgress: (percentage) => console.log(`Download: ${percentage}%`)
})

// Rate limiting for uploads (50KB/s)
const result = await fetch.post('https://api.example.com/upload', fileData, {
  maxRate: 50 * 1024, // 50KB/s
  onProgress: (percentage) => console.log(`Upload: ${percentage}%`)
})

// Cookie management (automatic in browser, manual in Node.js)
const response = await fetch.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.