Created
July 12, 2019 21:45
-
-
Save jerryvig/20c9fa2d7364325416c8ac5054718a29 to your computer and use it in GitHub Desktop.
http2 Client Example in TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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