h2client
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

h2client

A lightweight node js http2 (h2) client with automatic reconnection.



Installation

npm install h2client

Usage

import { connect } from 'h2client';

(async () => {
    const client = connect('http://localhost:10000', { 
        reconnect: true,
        reconnectInterval: 1000
    });
    client.on('connect', () => console.log('[HTTP2]', 'connected'));
    client.on('disconnect', () => console.log('[HTTP2]', 'disconnected'));
    client.on('reconnect', () => console.log('[HTTP2]', 'reconnecting...'));

    const stream = await client.request({ ':path': '/', ':method': 'GET' });
    stream.on('data', (data) => {
        console.log('[HTTP2]', data.toString());
    });
})();



API

Methods

connect: (url: string, options: SessionOptions | SecureSessionOptions)
Espose same interface as NodeJS http2 connect with additional options for reconnection.

interface SessionOptions extends ClientSessionOptions {
    reconnect?: boolean;
    reconnectInterval?: number;
}

interface SecureSessionOptions extends SecureClientSessionOptions {
    reconnect?: boolean;
    reconnectInterval?: number;
}

Demo

demo

Package Sidebar

Install

npm i h2client

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

5.93 kB

Total Files

4

Last publish

Collaborators

  • jzucchetto