Skip to content

Instantly share code, notes, and snippets.

@jerryvig
Created July 12, 2019 21:45
Show Gist options
  • Save jerryvig/20c9fa2d7364325416c8ac5054718a29 to your computer and use it in GitHub Desktop.
Save jerryvig/20c9fa2d7364325416c8ac5054718a29 to your computer and use it in GitHub Desktop.
http2 Client Example in TypeScript
// this is just a rudimentary http2 client example in TypeScript.
import * as http2 from 'http2';
function main(): void {
let data = '';
const client = http2.connect('https://www.google.com', {});
client.on('error', (err) => {
console.log('Client raised error.');
console.error(err);
});
const request = client.request({':path': '/'});
request.on('data', (chunk) => {
data += chunk;
});
request.on('end', () => {
console.log(data);
request.close();
});
request.on('close', () => {
client.close();
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment