@satvik-s/http2-client
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

http2-client

npm David node-current Snyk Vulnerabilities GitHub

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @satvik-s/http2-client

Weekly Downloads

1

Version

0.1.2

License

MIT

Unpacked Size

28 kB

Total Files

51

Last publish

Collaborators

  • satvik-s