Skip to main content

Fetch Interceptor

The Fetch interceptor overwrites the globalThis.fetch function to capture HTTP requests and apply mocks. It can be used for both server-side and client-side interception, wherever fetch is available.

Basic usage:

const { setupFetchInterceptor } = await import('request-mocking-protocol/fetch');

setupFetchInterceptor(() => {
// read and return headers of the incoming HTTP request
});

The actual function for retrieving incoming headers depends on the application framework.

For a complete example, see the server-side Next.js integration on how to use this interceptor.