@satvik-s/http2-client
v0.1.2
Published
node http2 wrapper
Downloads
4
Readme
http2-client
An opinionated HTTP/2 wrapper around native NodeJS module
http2-client provides a simple and accessible interface to make HTTP/2 requests to servers.
How it works
The Http2Client
class provides ability to the user to create instances of an HTTP/2 client which
can then be leveraged to call single/multiple APIs, single/multiple times over its lifetime.
Examples
GET Request
import { Http2Client } from '@satvik-s/http2-client';
const client = new Http2Client('https://test-service.com');
const resp = await client.request({
method: 'GET',
scheme: 'https',
path: '/v1/test-api',
});
console.log('status', resp.statusCode);
console.log('body', resp.body);
console.log('headers', resp.headers);
POST Request
import { Http2Client, PayloadType } from '@satvik-s/http2-client';
const client = new Http2Client('https://test-service.com');
const resp = await client.request({
method: 'POST',
scheme: 'https',
path: '/v1/test-api',
body: {
type: PayloadType.JSON,
data: {
hello: 'world',
}
},
});
console.log('status', resp.statusCode);
console.log('body', resp.body);
console.log('headers', resp.headers);
Contributing
Contributions are welcome! Read CONTRIBUTING.md
for more details.