Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Electron-Layer-repo-banner (1)

Requesty 1.2.1

Requesty is a lightweight JavaScript library for handling HTTP requests easily.


Installation

NPM :

npm i @limbusfoundation/requesty

Default Configuration

const 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
});

Main Properties

  • baseUrl: Base URL for all requests.
  • appName: Application name used for logging.
  • dataConversion: How the response is parsed (json or text).
  • 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.
    ...

Structure

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);

Methods

get(url, config, callback)

Performs a GET request.

await api.get("products/add",{});

post(url, config, callback)

Performs a POST request.

await api.post("products/add", { body: { name: "New Product" }});

put(url, config, callback)

Performs a PUT request (full update).

await api.put("products/1", { body: { name: "Updated Product" } });

patch(url, config, callback)

Performs a PATCH request (partial update).

await api.patch("/products/1", { body: { price: 19.99 } });

delete(url, config, callback)

Performs a DELETE request.

await api.delete("products/1", {});

cancelRequest(controller)

Cancels an ongoing request using its AbortController.

const { controller } = await api.get("/long-request");
api.cancelRequest(controller);

setBaseUrl(url)

Sets a new base URL for the instance.

api.setBaseUrl("https://newapi.example.com");

data(response)

Filter the data from response

const response = await api.get("products");

const myData = api.data(response);

console.log("My Requesta Data " + myData);

success(response)

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");

status(response)

Filter the status from response

const response = await api.get("products");

const status = api.status(response);

console.log("My Requesta Status " + status);

error(response)

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");

Request Options

Query

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=value

Route

you can add a list of routes in route option

await api.get("posts", { route: ["storys","yourPostId","otherRoute"]});

// https.yourdomain/posts/storys/yourPostId/otherRoute

or your can add directly inside the route :

await api.get("posts/storys/yourPostId/otherRoute");

// https.yourdomain/posts/storys/yourPostId/otherRoute

Body

you 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" }});

Header

you can add the Headers of your request in Header option

await api.post("posts", { header: { { "Authorization": "Bearer token" } });

Features

  1. Request Interceptors: Modify requests before sending.
  2. Response Interceptors: Handle or transform responses globally.
  3. Automatic Retries: Retry requests that fail with server errors.
  4. Timeouts: Abort requests that take too long.
  5. Caching: Stores responses to avoid repeated requests.
  6. Debug Mode: Detailed logging for easier debugging.
  7. Callback Support: Optional callback for each request.
  8. Promise-Based: All request methods return a Promise.
  9. Filter the Response: your can filter all data from response
  10. Custom Routes: your can add and control routes with a list of routes

and others...

Full Usage Example

  1. 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);
  1. 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)
}

Response Object

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 JSON and FormData bodies.
  • Timeout and retry logic ensures robust network handling.
  • Debug logs can be enabled for detailed info.

License

© 2025 Limbus Foundation & Community
This project is licensed under the MIT License.

About

Request Flow Library

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages