Native Node.js fetch implementation with axios interface
Just swap the import and use a lighter, native implementation without changing any code.
Tired of heavy HTTP libraries? one-request-4-all is a lightweight, native Node.js fetch implementation that provides the exact same interface as axios. Just change the import and enjoy a smaller bundle size!
|
Native Fetch Zero dependencies, pure Node.js |
Drop-in Replacement Same axios interface |
TypeScript First Full type safety |
Modern ES Modules Node.js 18+ ready |
Auto-Healing Smart error recovery |
# npm
npm install @purecore/reqify
# yarn
yarn add @purecore/reqify
# bun
bun add @purecore/reqifyimport reqify from "@purecore/reqify";
// GET request
const response = await reqify.get("https://api.example.com/users");
console.log(response.data);
// POST request
const newUser = await reqify.post("https://api.example.com/users", {
name: "John Doe",
email: "[email protected]",
});// Before (with axios)
import axios from "axios";
// After (with reqify)
import reqify from "@purecore/reqify";
// Same interface, same usage!
const response = await reqify.get("/api/users", {
headers: {
Authorization: "Bearer token",
},
});// GET, DELETE, HEAD, OPTIONS
await reqify.get<T>(url, config?)
await reqify.delete<T>(url, config?)
await reqify.head<T>(url, config?)
await reqify.options<T>(url, config?)
// POST, PUT, PATCH
await reqify.post<T>(url, data?, config?)
await reqify.put<T>(url, data?, config?)
await reqify.patch<T>(url, data?, config?)
// Generic request
await reqify<T>(config)
await reqify<T>(url, config)interface reqify<D = any> {
url: string;
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
headers?: Record<string, string>;
data?: D;
params?: Record<string, string | number | boolean>;
responseType?: 'json' | 'text' | 'stream';
}interface one-request-4-allResponse<T = any, D = any> {
data: T;
status: number;
statusText: string;
headers: Headers;
config: reqify<D>;
request: Response;
}one-request-4-all includes a powerful auto-healing system that automatically detects and recovers from common HTTP errors:
// Auto-healing is enabled by default
const response = await reqify.get("https://api.example.com/data", {
maxRetries: 3, // Number of retry attempts (default: 3)
timeout: 5000, // Initial timeout in ms (default: 5000)
autoHeal: true, // Enable auto-healing (default: true)
});
// Check if the request was healed
if (response.healed) {
console.log("β
Request was automatically healed!");
console.log("Message:", response.healMessage);
// Example: "Rate limited - retry after 1000ms"
}- 401 Unauthorized: Increases timeout and retries
- 403 Forbidden: Adjusts timeout for permission checks
- 413 Payload Too Large: Removes optional fields from payload (description, metadata, avatar, etc.)
- 422 Validation Error: Creates values based on expected types
- 429 Rate Limit: Respects
Retry-Afterheader or uses exponential backoff - Timeout: Progressively increases timeout (max 30s)
- Network Errors: Retries with increased timeout
- Parse Errors: Handles malformed JSON responses
When validation fails (422 error), one-request-4-all automatically creates values based on the expected type:
import { createValueFromType } from "@purecore/reqify";
createValueFromType("expected email"); // "[email protected]"
createValueFromType("must be number"); // 0
createValueFromType("expected uuid"); // "00000000-0000-0000-0000-000000000000"π Read the full Auto-Healing documentation
const response = await reqify.get("https://api.example.com/users", {
params: {
page: 1,
limit: 10,
active: true,
},
});
// GET https://api.example.com/users?page=1&limit=10&active=trueconst response = await reqify.post("https://api.example.com/users", userData, {
headers: {
Authorization: "Bearer token123",
"Content-Type": "application/json",
"X-API-Key": "your-api-key",
},
});// JSON (default)
const jsonData = await reqify.get("/api/data");
// Text response
const textData = await reqify.get("/api/text", {
responseType: "text",
});
// Stream response
const streamData = await reqify.get("/api/file", {
responseType: "stream",
});try {
const response = await reqify.get("/api/users/123");
console.log(response.data);
} catch (error) {
if (error.response) {
// Server responded with error status
console.log(error.response.status);
console.log(error.response.data);
} else if (error.request) {
// Network error
console.log("Network error");
} else {
// Other error
console.log("Error:", error.message);
}
}// Before
import axios from "axios";
// After
import reqify from "@purecore/reqify";// Before
const response = await axios.get("/api/users");
// After (same syntax works!)
const response = await reqify.get("/api/users");- β Same method signatures
- β Same response structure
- β Same error handling
- β Same configuration options
- β Full TypeScript support
β οΈ Some advanced axios features may not be implemented yet
npm test# Install dependencies
npm install
# Build
npm run build
# Run tests
npm testMIT License - see the LICENSE file for details.
Made with π by the PureCore team
