Requesty is a lightweight JavaScript library for handling HTTP requests easily.
NPM :
npm i @limbusfoundation/requestyconst configTemplate = {
baseUrl: "https://dummyjson.com",
appName: "myApp", // Application name for logs/debugging
dataConversion: "json", // "json" or "text"
header: {}, // Global headers
timeout: 5000, // Timeout in milliseconds
retry: 0, // Number of automatic retry attempts
debug: false // Enable debug logging
};Create a Requesty instance:
import { Requesty } from "requesty";
const api = new Requesty({
baseUrl: "https://dummyjson.com",
appName: "myApp",
dataConversion: "json",
header: { "Authorization": "Bearer token" },
timeout: 7000,
retry: 2,
debug: true
});- baseUrl: Base URL for all requests.
- appName: Application name used for logging.
- dataConversion: How the response is parsed (
jsonortext). - headers: Global headers for all requests.
- timeout: Request timeout in milliseconds.
- query: query params to get on request
- retry: Number of automatic retry attempts for 5xx errors.
- debug: Enable detailed logging.
- interceptRequest: Function to intercept and modify requests before sending.
- interceptResponse: Function to intercept responses after receiving.
- cache: Stores successfully fetched data.
...
All request methods return a Promise that resolves to an object containing { success, status, data, error, controller }.
They also support an optional callback as the last argument.
Request Mode Example - Callback | Promise | Async/Await
// Using callback
api.get("products", {}, (res) => {
console.log("Callback result:", res);
});
// Using Promise
api.get("products")
.then(res => console.log("Then result:", res))
.catch(err => console.error(err));
// Using async/await
const res = await api.get("products");
console.log("Await result:", res);Performs a GET request.
await api.get("products/add",{});Performs a POST request.
await api.post("products/add", { body: { name: "New Product" }});Performs a PUT request (full update).
await api.put("products/1", { body: { name: "Updated Product" } });Performs a PATCH request (partial update).
await api.patch("/products/1", { body: { price: 19.99 } });Performs a DELETE request.
await api.delete("products/1", {});Cancels an ongoing request using its AbortController.
const { controller } = await api.get("/long-request");
api.cancelRequest(controller);Sets a new base URL for the instance.
api.setBaseUrl("https://newapi.example.com");Filter the data from response
const response = await api.get("products");
const myData = api.data(response);
console.log("My Requesta Data " + myData);Filter if the request is ok ( success )
const response = await api.get("products");
const isOk = api.success(response);
if(isOk) console.log("the request is ok");
if(!isOk) console.log("the request is failed");Filter the status from response
const response = await api.get("products");
const status = api.status(response);
console.log("My Requesta Status " + status);Filter if the response is a error
const response = await api.get("products");
const isError = api.error(response);
if(isError) console.log("the request is Error");
if(!isError) console.log("the request is ok");you can add a list of query params in 'query' option
await api.get("categories", {query: { search: "mycategoryName", myParam : "value" }});
// https.yourdomain/categories?search=mycategoryName?myParam=valueyou can add a list of routes in route option
await api.get("posts", { route: ["storys","yourPostId","otherRoute"]});
// https.yourdomain/posts/storys/yourPostId/otherRouteor your can add directly inside the route :
await api.get("posts/storys/yourPostId/otherRoute");
// https.yourdomain/posts/storys/yourPostId/otherRouteyou can add the body of your request in body option
await api.post("posts", { body: JSON.stringfy(yourJsonBody)});
await api.post("posts", { body: { filmeName : "Iron Man" }});you can add the Headers of your request in Header option
await api.post("posts", { header: { { "Authorization": "Bearer token" } });- Request Interceptors: Modify requests before sending.
- Response Interceptors: Handle or transform responses globally.
- Automatic Retries: Retry requests that fail with server errors.
- Timeouts: Abort requests that take too long.
- Caching: Stores responses to avoid repeated requests.
- Debug Mode: Detailed logging for easier debugging.
- Callback Support: Optional callback for each request.
- Promise-Based: All request methods return a Promise.
- Filter the Response: your can filter all data from response
- Custom Routes: your can add and control routes with a list of routes
and others...
- requestyInstanceFile.js
import { Requesty } from '@limbusfoundation/requesty';
// relative path : "yourRelativeFilePath/@limbusfoundation/requesty/src/requesty.js"
const config = {
baseUrl : "https://dummyjson.com",
appName : "yourAppName",
dataConversion : "json",
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer token`,
}
};
export const requesty = new Requesty(config);- yourRequestFile.js
import { requesty } from "./requesty";
async function getProduct(){
const response = await requesty.get("product");
if(requesty.error(response)){
console.warn("Error to get product");
return;
}
const getProduct = requesty.data(response);
console.log("My Product : " + getProduct);
console.log("My Reponse : " + response)
}
All request methods return a Promise resolving to an object:
{
success: boolean, // true if HTTP status is 2xx
status: number, // HTTP status code
data: any, // Parsed response (JSON or text) or null
error: boolean, // true if request failed
controller: AbortController
}- Supports
JSONandFormDatabodies. - Timeout and retry logic ensures robust network handling.
- Debug logs can be enabled for detailed info.
© 2025 Limbus Foundation & Community
This project is licensed under the MIT License.