fetchloom
v1.0.3
Published
A smarter HTTP client built on top of Axios with retries, caching, key transformation, and clean errors.
Maintainers
Readme
fetchloom
A small Axios-based HTTP client with automatic retries, in-memory GET caching,
recursive snake_case to camelCase response transformation, and consistent
errors.
Install
npm install fetchloomNode.js 16+ and modern browser bundlers such as Vite and Webpack are supported.
Quick start
CommonJS:
const fetchloom = require("fetchloom");
const response = await fetchloom.get("https://api.example.com/users");
console.log(response.data);ES modules:
import fetchloom from "fetchloom";
const api = fetchloom.create({
baseURL: "https://api.example.com",
headers: { Accept: "application/json" },
});
const { data } = await api.get("/users");fetchloom returns Axios-compatible response objects. Automatic transformation is
applied to response.data.
Requests
await api.get("/users", { retry: 2, cache: 30 });
await api.post("/users", { first_name: "Ada" });
await api.put("/users/1", { first_name: "Grace" });
await api.delete("/users/1");The final argument accepts normal Axios request options plus:
| Option | Type | Default | Description |
| ----------- | ----------------- | ------- | ----------------------------------------- |
| retry | number | 3 | Retries after the initial request |
| cache | number or false | 60 | GET cache TTL in seconds; 0 disables |
| transform | boolean | true | Convert response object keys to camelCase |
Instance configuration also supports baseURL, headers, timeout, Axios
adapters, and other Axios configuration. The default timeout is 5000ms.
const api = fetchloom.create({
baseURL: "https://api.example.com",
retry: 3,
cache: 60,
transform: true,
timeout: 5000,
});Retry behavior
Network failures and HTTP 5xx responses are retried. HTTP 4xx responses and canceled requests are not retried. The default waits are 1 second, 2 seconds, and 3 seconds before the three retries.
Caching
Only successful GET responses are cached. POST, PUT, and DELETE requests are
never cached. Authenticated requests containing headers such as
Authorization, Cookie, or X-API-Key bypass the cache.
await api.get("/users", { cache: false });
api.clearCache();The cache is local to each fetchloom instance and is cleared when the process or browser page exits.
Transformation
Nested objects and arrays are transformed without changing the original response data:
// API data: { user_profile: { first_name: 'Ada' } }
const { data } = await api.get("/profile");
// data: { userProfile: { firstName: 'Ada' } }Use { transform: false } for endpoints where keys must be preserved.
Empty response bodies are normalized to null; primitive values are returned
unchanged.
Errors
All request failures are thrown as one of:
NetworkErrorfor connection and timeout failuresServerErrorfor HTTP 5xx responsesClientErrorfor HTTP 4xx responses
try {
await api.get("/private");
} catch (error) {
console.error(error.type);
console.error(error.message);
console.error(error.status);
console.error(error.url);
console.error(error.originalError);
}Sensitive authentication headers are removed from originalError.
Development
npm install
npm test
npm run coverage
npm run lint
npm run format:checkLicense
MIT
