1.0.8 • Published 10 months ago

fexjs v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago