acchio
v1.0.0
Published
A lightweight HTTP client for making requests in both browser and Node.js environments, inspired by Axios.
Maintainers
Readme
⚡ Acchio
An elegant and powerful HTTP client for Node.js and browsers — inspired by Axios, with a touch of magic! ✨
Acchio is a modern, fully typed, zero-dependency HTTP client with native support for interceptors, request cancellation, XML, and compatibility with both Node.js and browsers.
Because HTTP requests should feel magical, not complicated! 🎩✨
📚 Table of Contents
- 🚀 Installation
- 💡 Why Acchio?
- 🎯 Basic Usage
- 📋 Request Configuration
- 🔧 Interceptors
- 🚫 Request Cancellation
- 🌐 XML Support
- 🎨 Global Configuration
- 🚦 HTTP Methods
- 🎪 TypeScript Support
- 🔄 Environment Examples
- 🚨 Error Handling
- 📊 Comparison
- 📄 License
🚀 Installation
# npm
npm install acchio
# yarn
yarn add acchio
# pnpm
pnpm add acchio💡 Why Acchio?
- ✅ 100% TypeScript-native
- ✅ Works in Node.js and browsers
- ✅ Powerful interceptors
- ✅ Request cancellation
- ✅ Built-in XML support (auto-parse)
- ✅ Zero dependencies
- ✅ Familiar Axios-style API
🎯 Basic Usage
import acchio from "acchio";
// Simple GET
const response = await acchio.get("https://api.example.com/users");
console.log(response.data);
// POST with payload
await acchio.post("https://api.example.com/users", {
name: "John",
email: "[email protected]",
});📋 Request Configuration
const config = {
url: "/users",
method: "GET",
baseURL: "https://api.example.com",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer token",
},
params: { page: 1 },
timeout: 5000,
responseType: "json",
};Supported response types:
- json
- text
- blob
- arraybuffer
- xml
🔧 Interceptors
// Automatically attach token
acchio.interceptors.request.use((config) => {
config.headers.Authorization = `Bearer ${getToken()}`;
return config;
});
// Log requests
acchio.interceptors.request.use((config) => {
console.log(`🟡 ${config.method?.toUpperCase()} → ${config.url}`);
return config;
});
// Manipulate responses
acchio.interceptors.response.use((response) => {
console.log("🟢 Status:", response.status);
return response;
});🚫 Request Cancellation
const source = acchio.CancelToken.source();
acchio
.get("/api/data", { cancelToken: source.token })
.then((res) => console.log(res.data))
.catch((err) => {
if (acchio.isCancel(err)) console.log("Cancelled:", err.message);
});
// Cancel request
source.cancel("User aborted the request");🌐 XML Support
// Auto-parsed XML response
const res = await acchio.get("/feed.xml");
console.log(res.data);🎨 Global Configuration
import acchio from "acchio";
acchio.defaults.baseURL = "https://api.mysite.com";
acchio.defaults.timeout = 5000;
acchio.defaults.headers.common["X-App"] = "Acchio";Create custom instances:
const api = acchio.create({
baseURL: "https://api.company.com",
headers: { Authorization: "Bearer token" },
});🚦 HTTP Methods
acchio.get("/users");
acchio.post("/users", { name: "Maria" });
acchio.put("/users/1", { name: "John" });
acchio.patch("/users/1", { email: "[email protected]" });
acchio.delete("/users/1");🎪 TypeScript Support
interface User { id: number; name: string; email: string; }
const res = await acchio.get<User[]>('/api/users');
const users = res.data; // ✅ Fully typed🔄 Environment Examples
Node.js
const res = await acchio.get("https://api.github.com/users");React
useEffect(() => {
const source = acchio.CancelToken.source();
acchio
.get("/api/users", { cancelToken: source.token })
.then((res) => setUsers(res.data))
.catch(console.error);
return () => source.cancel();
}, []);🚨 Error Handling
try {
await acchio.get("/api/data");
} catch (error) {
if (acchio.isCancel(error)) console.log("Request cancelled");
else if (error.response) console.log("Status:", error.response.status);
}📊 Quick Comparison
| Feature | ⚡ Acchio | 📦 Axios | | ------------------ | -------------- | --------- | | TypeScript Typings | ✅ Native | ✅ | | Cancellation | ✅ | ✅ | | Interceptors | ✅ | ✅ | | Node.js + Browser | ✅ | ✅ | | XML Support | ✅ | ❌ | | Zero Dependencies | ✅ | ❌ | | Size | 🪶 Lightweight | 📦 Medium |
📄 License
MIT — Free for everyone! 🎉
🎊 Acknowledgements
Thank you for using Acchio! If you liked it, don’t forget to:
"Because HTTP requests should feel magical, not complicated!" 🎩✨
🔗 Project Links
