@xof/fetch-headers
v1.0.0
Published
Automatic browser-like HTTP headers wrapper for @xof/fetch with customizable request headers.
Readme
@xof/fetch-headers
Automatic browser-like HTTP headers wrapper for @xof/fetch.
Generate default browser headers automatically while keeping full control over custom user headers.
📄 License
🇮🇩 Bahasa Indonesia
Tentang
@xof/fetch-headers adalah wrapper untuk @xof/fetch yang secara otomatis menambahkan header HTTP bergaya browser pada setiap request.
Package ini membantu membuat request lebih mudah tanpa harus menulis header default secara manual.
Fitur:
- ✅ Otomatis membuat browser headers
- ✅ Support semua method dari
@xof/fetch - ✅ Custom headers tetap diprioritaskan
- ✅ Support CommonJS
- ✅ Ringan dan mudah digunakan
Instalasi
npm install @xof/fetch-headersPenggunaan
Request biasa
const fetch = require("@xof/fetch-headers");
const response = await fetch(
"https://example.com"
);
console.log(response);GET Request
const fetch = require("@xof/fetch-headers");
const response = await fetch.get(
"https://example.com/api"
);
console.log(response.data);POST Request
const fetch = require("@xof/fetch-headers");
const response = await fetch.post(
"https://example.com/api",
{
username: "user",
password: "secret"
}
);
console.log(response);Custom Headers
Header bawaan akan otomatis dibuat.
Jika user memberikan header sendiri, header tersebut akan digunakan.
const fetch = require("@xof/fetch-headers");
const response = await fetch.get(
"https://example.com",
{
headers: {
Authorization: "Bearer token",
"X-Custom": "value"
}
}
);
console.log(response);Menggunakan create instance
const fetch = require("@xof/fetch-headers");
const api = fetch.create({
timeout: 10000
});
api.get("https://example.com");Membuat Header Manual
const {
createHeaders
} = require("@xof/fetch-headers");
const headers = createHeaders(
"https://example.com"
);
console.log(headers);Output contoh:
{
Accept: "application/json",
Origin: "https://example.com",
Referer: "https://example.com/",
"User-Agent": "Mozilla/5.0 ..."
}🇬🇧 English
About
@xof/fetch-headers is a wrapper for @xof/fetch that automatically generates browser-like HTTP headers for every request.
It allows developers to send requests easily without manually creating common browser headers.
Features:
- ✅ Automatic browser headers
- ✅ Supports all
@xof/fetchmethods - ✅ Custom headers override defaults
- ✅ CommonJS support
- ✅ Lightweight and simple
Installation
npm install @xof/fetch-headersUsage
Basic Request
const fetch = require("@xof/fetch-headers");
const response = await fetch(
"https://example.com"
);
console.log(response);GET Request
const fetch = require("@xof/fetch-headers");
const response = await fetch.get(
"https://example.com/api"
);
console.log(response.data);POST Request
const fetch = require("@xof/fetch-headers");
const response = await fetch.post(
"https://example.com/api",
{
message: "hello"
}
);
console.log(response);Custom Headers
Default headers are generated automatically.
User-defined headers will override default values.
const fetch = require("@xof/fetch-headers");
fetch.get(
"https://example.com",
{
headers: {
Authorization: "Bearer token"
}
}
);Create Instance
const fetch = require("@xof/fetch-headers");
const api = fetch.create({
timeout: 5000
});
api.get("https://example.com");Manual Header Generation
const {
createHeaders
} = require("@xof/fetch-headers");
const headers = createHeaders(
"https://example.com"
);
console.log(headers);Dependencies
@xof/fetch1.0.1x-fakeua1.2.0
