{"_id":"@alok5953/tiny-http-client","_rev":"2-36dbbe6fa00e608483529f4d8c86e0e1","name":"@alok5953/tiny-http-client","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@alok5953/tiny-http-client","version":"1.0.0","keywords":["http","fetch","api","client","request","lightweight","universal","zero-dependencies","isomorphic"],"author":{"name":"Alok Kaushik"},"license":"MIT","_id":"@alok5953/tiny-http-client@1.0.0","maintainers":[{"name":"alok5953","email":"alokkaushik93@gmail.com"}],"homepage":"https://github.com/alokkaushik/tiny-http-client#readme","bugs":{"url":"https://github.com/alokkaushik/tiny-http-client/issues"},"dist":{"shasum":"42599e00c123ced306e9a0504c9bcf28afddc406","tarball":"https://registry.npmjs.org/@alok5953/tiny-http-client/-/tiny-http-client-1.0.0.tgz","fileCount":6,"integrity":"sha512-hdFL2+o06zlCLx/x9/NE8Ojwp55GL3Ep8P7lXnmszvOmCvHpdCyCkqZT6+EpHkc5zkfaYu4e+WIvzfOmMXwAgw==","signatures":[{"sig":"MEQCIBFhmRpaqJaH04ZWbywuasCIEx9UUxvnnPx5ObFUDaCeAiBbqbTaXlINlA/xx6AQ80KWlG8kE3FD/bLb/pOFp5npZg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15418},"main":"./src/http-client.js","type":"module","engines":{"node":">=18.0.0"},"exports":{".":"./src/http-client.js","./plugins":"./src/plugins.js"},"gitHead":"5d99ff15cca2e9409416b092b9e4fae71aa5475a","scripts":{"lint":"eslint src/","test":"node --experimental-vm-modules node_modules/jest/bin/jest.js","format":"prettier --write 'src/**/*.js'","prepare":"husky install"},"_npmUser":{"name":"alok5953","email":"alokkaushik93@gmail.com"},"repository":{"url":"git+https://github.com/alokkaushik/tiny-http-client.git","type":"git"},"_npmVersion":"10.9.2","description":"A lightweight, universal HTTP client wrapping native fetch API with zero dependencies","directories":{},"lint-staged":{"*.js":["eslint --fix","prettier --write"]},"_nodeVersion":"22.14.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","husky":"^9.0.11","eslint":"^8.57.0","prettier":"^3.2.5","@babel/core":"^7.24.0","lint-staged":"^15.2.2","@babel/preset-env":"^7.24.0"},"_npmOperationalInternal":{"tmp":"tmp/tiny-http-client_1.0.0_1741281582155_0.3723029581864856","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@alok5953/tiny-http-client","version":"1.0.1","description":"A lightweight, universal HTTP client wrapping native fetch API with zero dependencies","type":"module","main":"./src/http-client.js","exports":{".":"./src/http-client.js","./plugins":"./src/plugins.js"},"scripts":{"test":"node --experimental-vm-modules node_modules/jest/bin/jest.js","lint":"eslint src/","format":"prettier --write 'src/**/*.js'","prepare":"husky install"},"keywords":["http","fetch","api","client","request","lightweight","universal","zero-dependencies","isomorphic"],"author":{"name":"Alok"},"license":"MIT","engines":{"node":">=18.0.0"},"repository":{"type":"git","url":"git+https://github.com/alok5953/tiny-http-client.git"},"bugs":{"url":"https://github.com/alok5953/tiny-http-client/issues"},"homepage":"https://github.com/alok5953/tiny-http-client#readme","devDependencies":{"@babel/core":"^7.24.0","@babel/preset-env":"^7.24.0","eslint":"^8.57.0","husky":"^9.0.11","jest":"^29.7.0","lint-staged":"^15.2.2","prettier":"^3.2.5"},"lint-staged":{"*.js":["eslint --fix","prettier --write"]},"_id":"@alok5953/tiny-http-client@1.0.1","gitHead":"9c4d1d8faca3892c4bc46923469c5feabcde1760","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-+CqKMatiCVkAEy9i7aOe9fQwTaYfOkGb5Gjt4HQrGXdPEelLmMTayW8suxUAAhHJSLnhyjDLXRyEvT0xxOTrTA==","shasum":"6bd219a04d32cac3027aa83d024fedc62918994c","tarball":"https://registry.npmjs.org/@alok5953/tiny-http-client/-/tiny-http-client-1.0.1.tgz","fileCount":6,"unpackedSize":15439,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHAIQq0ydu2gu6iYNzJCeTB6rlpWWySzQK6Bacf3BuLpAiAnogFzAqpZt7L4izpp3bz7K0LpZt7UYfvwjZaxsHvDvQ=="}]},"_npmUser":{"name":"alok5953","email":"alokkaushik93@gmail.com"},"directories":{},"maintainers":[{"name":"alok5953","email":"alokkaushik93@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tiny-http-client_1.0.1_1741281859615_0.8129878413724216"},"_hasShrinkwrap":false}},"time":{"created":"2025-03-06T17:19:42.038Z","modified":"2025-03-06T17:24:19.995Z","1.0.0":"2025-03-06T17:19:42.346Z","1.0.1":"2025-03-06T17:24:19.851Z"},"bugs":{"url":"https://github.com/alok5953/tiny-http-client/issues"},"author":{"name":"Alok"},"license":"MIT","homepage":"https://github.com/alok5953/tiny-http-client#readme","keywords":["http","fetch","api","client","request","lightweight","universal","zero-dependencies","isomorphic"],"repository":{"type":"git","url":"git+https://github.com/alok5953/tiny-http-client.git"},"description":"A lightweight, universal HTTP client wrapping native fetch API with zero dependencies","maintainers":[{"name":"alok5953","email":"alokkaushik93@gmail.com"}],"readme":"# @alok5953/tiny-http-client\n\n[![npm version](https://img.shields.io/npm/v/@alok5953/tiny-http-client.svg)](https://www.npmjs.com/package/@alok5953/tiny-http-client)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Node.js Version](https://img.shields.io/node/v/@alok5953/tiny-http-client.svg)](https://nodejs.org)\n\nA modern, lightweight HTTP client that wraps the native fetch API for both browser and Node.js environments. Built with modern JavaScript practices and zero dependencies.\n\n## Why Choose This Library?\n\n- 🪶 **Truly Lightweight**: Zero dependencies, tiny bundle size (~2KB minified + gzipped)\n- ⚡️ **Modern & Fast**: Built on native fetch API\n- 🔄 **Smart Retries**: Built-in retry mechanism with exponential backoff\n- ⏱ **Timeout Control**: Automatic request timeouts using AbortController\n- 🔌 **Extensible**: Plugin system for custom functionality\n- 🌐 **Universal**: Works in both browser and Node.js (≥18)\n- 🛡️ **Type-Safe**: Written in JavaScript with JSDoc comments for TypeScript support\n\n## Installation\n\n```bash\nnpm install @alok5953/tiny-http-client\n```\n\n## Quick Start\n\n```javascript\nimport http from '@alok5953/tiny-http-client';\n\n// Simple GET request with automatic JSON parsing\nconst users = await http.get('https://api.example.com/users');\n\n// POST with JSON body\nconst newUser = await http.post('/api/users', {\n  name: 'John Doe',\n  email: 'john@example.com'\n});\n\n// Custom instance with advanced configuration\nconst api = new HttpClient('https://api.example.com', {\n  timeout: 5000,\n  retries: 3,\n  retryDelay: 1000,\n  headers: {\n    'Accept': 'application/json'\n  }\n});\n```\n\n## Features\n\n### Automatic Retries\n\n```javascript\n// Retry failed requests automatically\nconst api = new HttpClient('https://api.example.com', {\n  retries: 3,           // Number of retry attempts\n  retryDelay: 1000      // Base delay (uses exponential backoff)\n});\n\n// The client will automatically retry failed requests\n// with increasing delays: 1s, 2s, 4s\nconst data = await api.get('/unstable-endpoint');\n```\n\n### Plugin System\n\n```javascript\nimport { authPlugin, cachePlugin, loggingPlugin } from '@alok5953/tiny-http-client/plugins';\n\n// Authentication plugin\nhttp.use(authPlugin('your-token'));\n\n// Caching plugin with TTL\nhttp.use(cachePlugin(60000)); // 1 minute cache\n\n// Logging plugin\nhttp.use(loggingPlugin());\n\n// Custom plugin\nhttp.use(client => {\n  const originalRequest = client.request.bind(client);\n  client.request = async (url, options) => {\n    console.log(`Request to: ${url}`);\n    const response = await originalRequest(url, options);\n    console.log(`Response status: ${response.status}`);\n    return response;\n  };\n});\n```\n\n## API Reference\n\n### HttpClient\n\n```javascript\n// Constructor\nnew HttpClient(baseUrl?: string, options?: HttpClientOptions)\n\n// Instance methods\nrequest(url: string, options?: RequestOptions): Promise<any>\nget(url: string, options?: RequestOptions): Promise<any>\npost(url: string, data?: any, options?: RequestOptions): Promise<any>\nput(url: string, data?: any, options?: RequestOptions): Promise<any>\ndelete(url: string, options?: RequestOptions): Promise<any>\nuse(plugin: Plugin): HttpClient\n```\n\n### Options\n\n```javascript\ninterface HttpClientOptions {\n  timeout?: number;        // Request timeout in ms (default: 10000)\n  retries?: number;        // Number of retry attempts (default: 0)\n  retryDelay?: number;     // Base delay between retries in ms (default: 1000)\n  headers?: Headers;       // Default headers for all requests\n  parseJson?: boolean;     // Auto-parse JSON responses (default: true)\n  [key: string]: any;      // Any valid fetch options\n}\n```\n\n### Error Handling\n\n```javascript\ntry {\n  const data = await http.get('/api/users');\n} catch (error) {\n  if (error.name === 'HttpError') {\n    console.error(`HTTP ${error.status}:`, error.message);\n    // Access the original response\n    console.error('Response:', error.response);\n  } else if (error.name === 'TimeoutError') {\n    console.error(`Request timed out after ${error.timeout}ms`);\n  }\n}\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Run tests\nnpm test\n\n# Lint code\nnpm run lint\n\n# Format code\nnpm run format\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Author\n\n**Alok**\n\n- GitHub: [@alok5953](https://github.com/alok5953)\n- npm: [@alok5953](https://www.npmjs.com/~alok5953)\n- LinkedIn: [Alok Kaushik](https://www.linkedin.com/in/alok-kaushik-b67128267/)\n\n## Acknowledgments\n\n- Inspired by the need for a lightweight, modern HTTP client\n- Built with modern JavaScript features and best practices\n- Zero dependencies for minimal bundle size and maximum reliability\n","readmeFilename":"README.md"}