setu.js
Version:
A lightweight HTTP client for Node.js and the browser, with smart adapter selection.
166 lines (111 loc) • 3.97 kB
Markdown
# Setu.js – Modern HTTP Client for JavaScript



Setu.js is a minimal, powerful, and highly customizable HTTP client built for modern JavaScript applications. With built-in support for **retries**, **timeouts**, **streaming**, and **smart defaults**, Setu.js is ideal for both frontend and backend environments.
**Framework Agnostic** - Works with React, Vue, Angular, Next.js, Express, and virtually any JavaScript/TypeScript framework! See [FRAMEWORK_COMPATIBILITY.md](./FRAMEWORK_COMPATIBILITY.md) for details.
## ✨ Features
* 📦 Lightweight and zero-config
* 🔁 Built-in retry mechanism with exponential backoff
* ⏱️ Timeout support for requests
* 📡 Streaming and upload/download progress
* 🧠 Adapter-based engine (browser + Node.js)
* 💎 Clean API inspired by Axios and modern fetch
* ⚡ **C++ Optimization Layer** - Optional native addon for 2-5x performance boost
## 🚀 Installation
```bash
npm install setu.js
```
or
```bash
yarn add setu.js
```
**Note**: The C++ optimization module is optional. If you don't have a C++ compiler installed, Setu.js will automatically use JavaScript implementations. The package works perfectly either way!
## 📦 Basic Usage
```js
import setu from 'setu.js';
const response = await setu.get('/api/users');
console.log(response.data);
```
```js
await setu.post('/api/upload', {
body: formData,
onUploadProgress: (progress) => {
console.log(`${progress.loaded}/${progress.total}`);
}
});
```
## 🛠 Core API
### `setu.get(url, options)`
* Make a `GET` request
* Accepts optional retries, timeout, and headers
### `setu.post(url, options)`
* POST request with JSON or multipart form support
* Supports `onUploadProgress`
### `setu.put(url, options)` / `setu.delete()`
* Standard REST methods supported
### Request Options
```ts
{
headers?: Record<string, string>;
body?: any;
retries?: number; // Default: 0
retryDelay?: number; // Default: 1000ms
timeout?: number; // Default: 0 (no timeout)
onUploadProgress?: (progress) => void;
onDownloadProgress?: (progress) => void;
}
```
## ♻ Retry Example
```js
const response = await setu.get('/api/reliable-data', {
retries: 3,
retryDelay: 1000
});
```
## ⏱ Timeout Example
```js
await setu.get('/api/slow-endpoint', {
timeout: 3000 // fail after 3s
});
```
## ⚡ C++ Optimization Example
Enable native C++ optimizations for 2-5x performance improvements:
```js
await setu.get('/api/data', {
optimized: true // Use C++ optimized functions
});
```
**Note**: The native module is optional and builds automatically. Setu.js falls back to JavaScript if unavailable. See [OPTIMIZATION.md](./OPTIMIZATION.md) for details.
## 🎯 Framework Support
Setu.js works with **any JavaScript/TypeScript framework**:
### Frontend
✅ React • Vue.js • Angular • Svelte • Next.js • Nuxt.js • Remix • Solid.js
### Backend
✅ Express • Fastify • Koa • NestJS • Hapi • FastAPI (via Node.js)
### Runtimes
✅ Node.js • Deno • Bun • Cloudflare Workers • AWS Lambda • Vercel Edge
**See [FRAMEWORK_COMPATIBILITY.md](./FRAMEWORK_COMPATIBILITY.md) for detailed examples and integration guides.**
## 🔗 Learn More & Full Documentation
➡️ Full docs with examples, advanced usage and integration guides:
**[https://setujs.dev](https://setujsdocs.vercel.app)**
## ❤️ Contributing
We welcome contributions! Open issues, suggest features, or improve the docs.
```bash
git clone https://github.com/chaitu426/setu.js.git
cd setu.js
npm install
npm run dev
```
## 📄 License
MIT © [Chaitanya Abhade](https://github.com/chaitu426)
Built with ❤️ for the JavaScript community.