1.2.0 • Published 6 months ago

nakadachi v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Usage

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.

Details

/* 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 )
1.2.0

6 months ago

1.1.0

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago