A modern, universal HTTP client library for TypeScript and JavaScript that supports fetch and XHR fallback, timeouts, retries, interceptors, and progress reporting.
| Feature | Browser | Node.js |
|---|---|---|
fetcher.get/post/... |
✅ | ✅ |
downloadWithProgress() |
✅ | ❌ |
postWithUploadProgress() |
✅ | ❌ |
import fetcher from '@tripathirajan/fetcher';
const res = await fetcher.get('https://api.example.com/data');
const json = await res.json();
npm install @tripathirajan/fetcher
import fetcher from '@tripathirajan/fetcher';
// example usage here...
const fetcher = require('@tripathirajan/fetcher').default;
// example usage here...
<script src="https://unpkg.com/@tripathirajan/fetcher@<VERSION>/dist/fetcher.min.js"></script>
<script>
fetcher
.get('https://api.example.com/data')
.then((res) => res.json())
.then((data) => console.log(data));
</script>
fetcher.create(config)Creates a new Fetcher instance.
| Option | Type | Description |
|---|---|---|
baseURL |
string |
Base URL for all requests |
headers |
Record<string, string> |
Default headers |
timeout |
number |
Timeout in milliseconds |
retries |
number |
Number of retry attempts |
credentials |
"omit" | "same-origin" | "include" |
Credential policy for cross-origin requests |
All methods return a native Response object. You must call .json(), .text(), etc. to parse.
get(url, config?)post(url, body, config?)put(url, body, config?)delete(url, config?)downloadWithProgress(url, onProgress, config?) (Browser only)postWithUploadProgress(url, body, onUploadProgress, config?) (Browser only)Full API documentation:
https://tripathirajan.github.io/fetcher/
⚠️
downloadWithProgressandpostWithUploadProgressare only available in browser environments and will throw an error if used in Node.js.
See the examples folder for Node.js and Browser usage.
Run all pre-checks before build:
npm run prebuild
Note: The
prebuildscript runs automatically beforenpm run build. It ensures linting, formatting, and tests are successful before generating build output.
Contributions, issues and feature requests are welcome! Feel free to open an issue or submit a pull request.
If you find this library useful, consider starring the repo or buying me a coffee.
MIT © 2025 Rajan Tripathi