A lightweight, class-based HTTP client built on top of fetch().
QuykFetch gives you a clean, readable API for sending requests, handling responses, managing headers, parsing data, and normalizing errors without pulling in a heavy dependency.
| Feature | Description |
|---|---|
| Class-based API | Create reusable client instances with shared defaults |
| Lightweight | Small, focused API surface with minimal overhead |
Built on fetch() |
Uses the native web standard under the hood |
| Request helpers | Includes get, post, put, patch, delete, and request |
| Shared defaults | Configure baseURL, headers, timeout, hooks, and more once |
| Query params | Automatically serializes query parameters |
| Smart body handling | Supports JSON, FormData, strings, URLSearchParams, blobs, and buffers |
| Auto response parsing | Parses JSON, text, blob, arrayBuffer, or raw responses |
| Normalized errors | Consistent error objects for failed requests |
| Hooks | Lightweight request, response, and error hooks |
| Scalable structure | Clean internals that can grow with your project |
npm install quykfetchimport QuykFetch from "quykfetch";
const api = new QuykFetch({
baseURL: "https://api.example.com",
timeout: 10000,
headers: {
"X-App": "QuykFetch"
}
});
const response = await api.get("/users");
console.log(response.status);
console.log(response.data);const api = new QuykFetch({
baseURL: "https://api.example.com",
timeout: 15000,
headers: {
Accept: "application/json"
}
});const response = await api.get("/users");
console.log(response.ok);
console.log(response.status);
console.log(response.data);const response = await api.get("/users", {
params: {
page: 1,
search: "JhonDoe",
tags: ["active", "admin"]
}
});
console.log(response.data);const response = await api.post("/users", {
name: "JhonDoe",
role: "admin"
});
console.log(response.data);const response = await api.put("/users/42", {
name: "Updated Name"
});const response = await api.patch("/users/42", {
role: "editor"
});await api.delete("/users/42");const response = await api.request({
url: "/users",
method: "GET",
headers: {
"X-Debug": "true"
}
});QuykFetch returns a normalized response object.
| Property | Type | Description |
|---|---|---|
ok |
boolean |
Whether the request succeeded |
status |
number |
HTTP status code |
statusText |
string |
HTTP status text |
url |
string |
Final response URL |
headers |
object |
Response headers as a plain object |
data |
any |
Parsed response body |
raw |
Response |
Native fetch response |
const response = await api.get("/users");
console.log(response.data);
console.log(response.status);QuykFetch automatically handles common body types.
| Body Type | Behavior |
|---|---|
| Plain object | Automatically JSON stringified |
FormData |
Passed through untouched |
URLSearchParams |
Sent as form data |
string |
Sent as plain text |
Blob / ArrayBuffer |
Passed through directly |
await api.post("/users", {
name: "JhonDoe",
email: "JhonDoe@example.com"
});const form = new FormData();
form.append("avatar", fileInput.files[0]);
await api.post("/upload", form);const form = new URLSearchParams();
form.append("email", "JhonDoe@example.com");
form.append("password", "secret");
await api.post("/login", form);const api = new QuykFetch({
headers: {
"X-App": "QuykFetch"
}
});await api.get("/users", {
headers: {
Authorization: "Bearer your_token_here"
}
});api.setHeader("X-Client", "dashboard");
api.removeHeader("X-Client");api.setToken("your_token_here");
api.clearToken();You can also provide a custom auth type:
api.setToken("your_token_here", "Token");const api = new QuykFetch({
timeout: 10000
});await api.get("/reports", {
timeout: 30000
});By default, QuykFetch uses responseType: "auto" and parses the response based on its content type.
| Value | Description |
|---|---|
auto |
Automatically detect response format |
json |
Parse as JSON |
text |
Parse as text |
blob |
Parse as blob |
arrayBuffer |
Parse as array buffer |
raw |
Return the raw fetch Response object |
const response = await api.get("/report.txt", {
responseType: "text"
});
console.log(response.data);QuykFetch throws normalized errors to make failures easier to handle.
try {
await api.get("/missing-route");
} catch (error) {
console.log(error.name);
console.log(error.message);
console.log(error.status);
console.log(error.statusText);
console.log(error.url);
console.log(error.method);
console.log(error.data);
}| Property | Description |
|---|---|
name |
Error class name |
message |
Error message |
status |
HTTP status code if available |
statusText |
HTTP status text if available |
url |
Request URL |
method |
Request method |
data |
Parsed error response data if available |
headers |
Response headers if available |
cause |
Original underlying error |
isTimeout |
Whether the request timed out |
isAbort |
Whether the request was aborted |
QuykFetch supports lightweight hooks for request and response flow.
const api = new QuykFetch({
hooks: {
beforeRequest: ({ url, options }) => {
console.log("Request:", url, options);
return { url, options };
},
afterResponse: (response) => {
console.log("Response:", response.status);
return response;
},
onError: (error) => {
console.error("Request failed:", error);
throw error;
}
}
});Create a new client from an existing one while preserving defaults.
const api = new QuykFetch({
baseURL: "https://api.example.com",
headers: {
Accept: "application/json"
}
});
const adminApi = api.extend({
headers: {
Authorization: "Bearer admin_token"
}
});QuykFetch is a good fit when you want:
- a cleaner alternative to raw
fetch() - reusable API clients
- shared defaults across requests
- automatic parsing and body handling
- better error handling without a large dependency
MIT