For basic logging, you can use:
// Assuming you've imported Nakadachi.
// Run the hook command
Nakadachi.hook();
// After hooking, add a middleware.
Nakadachi.addMiddleware( interceptor => {
// Log the requests only
if ( interceptor.type === 'request' )
console.log( interceptor.request );
} );
// Make any Fetch or XMLHttpRequest calls here.
For intercepting requests, you can use:
// Assuming you've imported Nakadachi and hooked it.
Nakadachi.addMiddleware( interceptor => {
// Log the requests only
if ( interceptor.type === 'request'
&& interceptor.request.url.endsWith( '/debug' ) )
interceptor.intercept(
new Nakadachi.HTTPCode( '200', 'OK' ),
{ /* Leaving headers empty */ },
JSON.stringify( {
isDebug: true
} )
);
} );
// Make any Fetch or XMLHttpRequest calls here.
/* Hooks onto the network calls */
Nakadachi.Hook()
/* Middleware Management */
Nakadachi.addMiddleware( mw: Function )
Nakadachi.removeMiddleware( mw: Function )
/* Helper classes */
new Nakadachi.HTTPCode( code: Number, status: String )
/* Internals */
InterceptableRequest.type: String
InterceptableRequest.request: Request
InterceptableRequest.intercept( code: HTTPCode, headers: Object, data: Any )