sending http/2 POST request in Node.js

2k views Asked by At

How can send an http/2 post request in Node.js? I want to send the following request.

curl --http2 "POST" "http://hostname:8088/query-stream" -d $'{"sql": "SELECT * FROM `USERPROFILE` EMIT CHANGES;", "properties": {"ksql.streams.auto.offset.reset": "earliest" } }'
1

There are 1 answers

3
torusJKL On

The package fetch-h2 has http/2 support:

import { fetch } from 'fetch-h2'

const url = 'https://hostname:8088/query-stream'
const method = 'POST';
const json = {"sql": "SELECT * FROM `USERPROFILE` EMIT CHANGES;", "properties": {"ksql.streams.auto.offset.reset": "earliest" } };
 
const response = await fetch( url, { method, json } );

Note that by default fetch-h2 uses http/1.1 for http:// addresses. Either change the URL or configure fetch-h2 to explicitly use http/2 even for http:// requests.