h2client
v1.0.2
Published
A lightweight http2 (h2) client with automatic reconnection.
Downloads
9
Maintainers
Readme
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;
}