fexjs
v1.0.10
Published
A lightweight and powerful Fetch API wrapper with interceptors, cancel tokens, and timeout support.
Downloads
191
Maintainers
Readme
fexjs 🚀
A lightweight and powerful Fetch API wrapper with interceptors, cancel tokens, and timeout support.
✨ 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