grabo
v1.0.1
Published
Grabo is a fast and lightweight HTTP client.
Maintainers
Readme
Grabo - High-Performance HTTP Client
Grabo is a fast, lightweight HTTP client designed for modern JavaScript applications. It simplifies making HTTP requests with built-in interceptors, timeouts, and automatic retries. Whether you're working in Node.js or the browser, Grabo provides an intuitive API for handling network requests efficiently.
Features
- ✅ Simple & Easy-to-Use API
- ✅ Supports GET, POST, PUT, PATCH, DELETE
- ✅ Request & Response Interceptors
- ✅ Timeout Handling
- ✅ Automatic Retries
- ✅ Works in Node.js & Browsers
- ✅ CDN Support
Installation
Node.js (NPM)
npm install graboCDN (jsDelivr)
<script src="https://cdn.jsdelivr.net/npm/grabo/dist/grabo.min.js"></script>CDN (UNPKG)
<script src="https://unpkg.com/grabo/dist/grabo.min.js"></script>Quick Start
Import Grabo
Node.js / ES Modules
const Grabo = require("grabo");
const api = new Grabo({
baseURL: "https://jsonplaceholder.typicode.com",
timeout: 5000, // 5 seconds timeout
});CDN / Browser
<script src="https://cdn.jsdelivr.net/npm/grabo/dist/grabo.min.js"></script>
<script>
const api = new Grabo({ baseURL: "https://jsonplaceholder.typicode.com" });
</script>Making Requests
GET Request
api.get("/posts/1").then((response) => {
console.log(response.data);
});POST Request
api.post("/posts", { title: "Hello", body: "World" }).then((response) => {
console.log(response.data);
});PUT Request
api.put("/posts/1", { title: "Updated" }).then((response) => {
console.log(response.data);
});PATCH Request
api.patch("/posts/1", { title: "Partial Update" }).then((response) => {
console.log(response.data);
});DELETE Request
api.delete("/posts/1").then((response) => {
console.log("Deleted Successfully");
});Configuration Options
You can pass the following options when creating a Grabo instance:
| Option | Type | Default | Description |
| ------------ | ------ | ------- | ---------------------------- |
| baseURL | string | '' | Base URL for requests |
| headers | object | {} | Default headers for requests |
| timeout | number | 10000 | Timeout in milliseconds |
| retries | number | 0 | Number of automatic retries |
| retryDelay | number | 1000 | Delay between retries (ms) |
Example:
const api = new Grabo({
baseURL: "https://example.com/api",
headers: { Authorization: "Bearer token" },
timeout: 5000,
retries: 3,
});Interceptors
Grabo allows you to modify requests and responses using interceptors.
Request Interceptor
api.useRequestInterceptor((config) => {
config.headers["X-Custom-Header"] = "Hello";
return config;
});Response Interceptor
api.useResponseInterceptor((response) => {
console.log("Response Received:", response);
return response;
});Timeout Handling
If a request exceeds the specified timeout, it will be automatically aborted.
const api = new Grabo({ timeout: 3000 });
api.get("/slow-endpoint").catch((error) => console.error(error.message)); // "Request timed out after 3000ms"Automatic Retries
You can configure automatic retries for failed requests.
const api = new Grabo({ retries: 3, retryDelay: 2000 });
api
.get("/unstable-endpoint")
.then((response) => console.log(response.data))
.catch((error) => console.error("Failed after 3 retries"));Error Handling
Grabo provides structured error handling for failed requests.
api.get("/invalid-endpoint").catch((error) => {
console.error("Error:", error.message);
});Support My Work
If you find Grabo useful and want to support its development, you can Buy Me a Coffee! Your support helps keep the project growing. ❤️
License
Grabo is open-source and released under the MIT License.
