Skip to content

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.

import { createHttpInterceptor } from "@xtandard/lib/web";
const interceptor = createHttpInterceptor();
// Intercept all POST requests to a specific path
const handle = interceptor.addRule({
name: "api-posts",
path: "/api/posts",
method: "POST",
onIntercept: (event) => {
console.log("Intercepted:", event.method, event.url, event.response.body);
},
});
// Stop intercepting
handle.stop();
// Remove all patches and restore originals
interceptor.restore();