Skip to content

neotesk/nethop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nethop is a Minimal Network Hook Library for Web Testing and Mock Data

Usage

For basic logging, you can use:

// Assuming you've imported Nethop.
// Run the hook command
Nethop.hook();

// After hooking, add a middleware.
Nethop.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 Nethop and hooked it.
Nethop.addMiddleware( interceptor => {
    // Log the requests only
    if ( interceptor.type === 'request'
        && interceptor.request.url.endsWith( '/debug' ) )
        interceptor.intercept(
            new Nethop.HTTPCode( '200', 'OK' ),
            { /* Leaving headers empty */ },
            JSON.stringify( {
                isDebug: true
            } )
        );
} );

// Make any Fetch or XMLHttpRequest calls here.

Details

/* Hooks onto the network calls */
Nethop.Hook()

/* Middleware Management */
Nethop.addMiddleware( mw: Function )
Nethop.removeMiddleware( mw: Function )

/* Helper classes */
new Nethop.HTTPCode( code: Number, status: String )

/* Internals */
InterceptableRequest.type: String
InterceptableRequest.request: Request
InterceptableRequest.intercept( code: HTTPCode, headers: Object, data: Any )

About

Minimal Network Hook Library for Web Testing and Mock Data

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published