HttpMethod
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";Defined in: intercept-http.ts:33
HTTP interceptor for fetch and XMLHttpRequest.
Patches whichever of the two the runtime has (servers: fetch only) to
capture requests/responses based on configurable rules.
Useful for debugging, analytics, monitoring, and testing.
Example
Section titled “Example”import { createHttpInterceptor } from "@xtandard/lib/web";
const interceptor = createHttpInterceptor();
// Intercept all POST requests to a specific pathconst handle = interceptor.addRule({ name: "api-posts", path: "/api/posts", method: "POST", onIntercept: (event) => { console.log("Intercepted:", event.method, event.url, event.response.body); },});
// Stop interceptinghandle.stop();
// Remove all patches and restore originalsinterceptor.restore();