import { ApiClient, RequestCache } from "bytekit";
const cache = new RequestCache({ ttl: 60000 });
const api = new ApiClient({
baseUrl: "https://api.example.com",
interceptors: {
request: async (url, init) => {
const cached = cache.get(url);
if (cached) {
return [url, { ...init, signal: AbortSignal.abort() }];
}
return [url, init];
},
response: async (response) => {
const data = await response.clone().json();
cache.set(response.url, data);
return response;
}
}
});