UNPKG

fetchbee

Version:

A lightweight JS library to simplify all kinds of API calls.

153 lines (108 loc) โ€ข 2.51 kB
# ๐Ÿ 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**