The request URL or Request object
Optional
init: RequestInitOptional request configuration
A promise that resolves to a FetchDecoratorResponse
// Basic GET request
const response = await fetchDecorator("https://api.example.com/data");
console.log(response.data); // Parsed response data
console.log(response.requestHash); // Unique request hash
// POST request with JSON body
const response = await fetchDecorator("https://api.example.com/data", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "test" })
});
// Using Request object
const request = new Request("https://api.example.com/data", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "test" })
});
const response = await fetchDecorator(request);
// Handling different response types
const response = await fetchDecorator("https://api.example.com/data");
if (response.headers.get("content-type")?.includes("application/json")) {
// Data is already parsed as JSON
console.log(response.data);
} else if (response.headers.get("content-type")?.includes("text/")) {
// Data is already parsed as text
console.log(response.data);
} else {
// Data is a Blob
const blob = response.data as Blob;
// Handle blob data
}
A decorator function that wraps the native fetch API with additional features: