fetchbee
Version:
A lightweight JS library to simplify all kinds of API calls.
153 lines (108 loc) โข 2.51 kB
Markdown
# ๐ FetchBee
**FetchBee** is a lightweight, modern JavaScript utility library built on top of native `fetch`, designed to simplify HTTP API calls โ from basic `GET` to advanced filtering, pagination, search, and full CRUD operations.
## ๐ฆ Installation
```bash
npm install fetchbee
```
## ๐ Quick Usage
Import what you need:
```js
import {
getFetch,
getById,
getWithPagination,
getWithSearch,
getWithDate,
getCombined,
postFetch,
putFetch,
patchFetch,
deleteFetch
} from "fetchbee";
```
## ๐ API Reference
### ๐ฅ GET Methods
#### ๐น `getFetch(url, options?)`
Basic GET request.
```js
await getFetch("https://api.com/data");
```
#### ๐น `getById(baseUrl, id, options?)`
Fetch a resource by ID.
```js
await getById("https://api.com/users", 123);
```
#### ๐น `getWithPagination(baseUrl, page, size, options?)`
GET paginated results.
```js
await getWithPagination("https://api.com/items", 1, 20);
```
#### ๐น `getWithSearch(baseUrl, searchTerm, options?)`
GET with `?search=term`.
```js
await getWithSearch("https://api.com/items", "lamp");
```
#### ๐น `getWithDate(baseUrl, from, to, options?)`
GET with date filters `?from=YYYY-MM-DD&to=YYYY-MM-DD`.
```js
await getWithDate("https://api.com/logs", "2024-01-01", "2024-01-31");
```
#### ๐น `getCombined(baseUrl, config)`
Advanced GET: combines ID, search, date, pagination.
```js
await getCombined("https://api.com/products", {
id: 42,
search: "bulb",
page: 1,
size: 10,
from: "2024-01-01",
to: "2024-01-31",
headers: {
Authorization: "Bearer token"
}
});
```
### โ๏ธ POST / PUT / PATCH / DELETE
#### ๐ธ `postFetch(url, body, options?)`
```js
await postFetch("https://api.com/items", {
name: "LED Lamp",
price: 199
});
```
#### ๐ธ `putFetch(url, body, options?)`
```js
await putFetch("https://api.com/items/5", {
name: "Updated Name"
});
```
#### ๐ธ `patchFetch(url, body, options?)`
```js
await patchFetch("https://api.com/items/5", {
price: 99
});
```
#### ๐ธ `deleteFetch(url, options?)`
```js
await deleteFetch("https://api.com/items/5");
```
## โ๏ธ Options Object
All methods accept an `options` object:
```js
{
headers: { Authorization: "Bearer token" },
query: { key1: "value1", key2: "value2" }
}
```
## ๐งช Run the API Tester UI
1. Open `index.html` in any browser.
2. It loads `FetchBeeTester.js` and allows you to test all API methods.
## ๐ก Author
Made with ๐ by **Biswajeet Mishra**