Package detail

fexjs

gloomystore35MIT1.0.10

A lightweight and powerful Fetch API wrapper with interceptors, cancel tokens, and timeout support.

fetch, axios-alternative, http-client, typescript

readme

fexjs 🚀

A lightweight and powerful Fetch API wrapper with interceptors, cancel tokens, and timeout support.

npm license issues

✨ Features

  • Interceptors: Request & Response hooks like Axios.
  • Timeout Support: Automatically aborts slow requests.
  • Cancel Tokens: Similar to Axios' CancelToken.
  • Base URL Support: Define base URLs for API calls.
  • Lightweight & No Dependencies: Uses only native fetch.

Funding!

https://github.com/sponsors/gloomystore

📦 Installation

npm install fexjs

🚀 Usage

🔹 Basic GET Request

import fex from "fexjs";

fex.get("https://jsonplaceholder.typicode.com/posts/1")
  .then((res) => console.log(res.data))
  .catch((err) => console.error(err));

🔹 POST Request with JSON Body

fex.post("https://jsonplaceholder.typicode.com/posts", {
  title: "New Post",
  body: "This is the content.",
  userId: 1
}).then((res) => console.log(res.data));

🔹 Using Interceptors

const fexInstance = fex.create({
  baseURL: "https://api.example.com",
  timeout: 5000
});

fexInstance.interceptors.request.use((config) => {
  config.headers["Authorization"] = "Bearer mytoken";
  return config;
});

📜 API Reference

fex.create(config)

Creates a new instance of fex with custom defaults.

fex.get(url, config)

Sends a GET request.

fex.post(url, data, config)

Sends a POST request with a JSON body.

fex.options(url, config)

Sends an OPTIONS request.

🛠 Development

git clone https://github.com/gloomystore/fexjs.git
cd fexjs
npm install
npm run build

📜 License

MIT © gloomystore

changelog

📜 Changelog

All notable changes will be documented in this file.

[1.0.0] - 2025-03-06

🎉 Added

  • Initial release of fexjs.
  • Support for GET, POST, OPTIONS requests.
  • Interceptors for request & response.
  • Cancel tokens for request cancellation.
  • Timeout support.

[1.0.5] - 2025-03-07

🔧 Improved

  • Enhanced TypeScript typings for stricter type safety.
  • Improved error handling for response interceptors.

🐛 Fixed

  • https module is now only used in Node.js environments to prevent browser-related issues.
  • Ensured withCredentials and mode options cannot be used together to avoid conflicts.

[1.0.8] - 2025-03-07

🐛 Fixed

  • removed https module and NODE_TLS_REJECT_UNAUTHORIZED settings

[1.0.9] - 2025-03-26

🐛 Fixed

  • added FexError type.