A BHTTP (Binary Representation of HTTP Messages) Encoder and Decoder written in TypeScript.
Attributes
Includes Deno configuration
Repository
Current version released
2 years ago
bhttp-js
A TypeScript implementation of Binary Representation of HTTP Messages (RFC9292) using Request/Response interface of the Fetch API.
This module works on web browsers, Node.js, Deno.
Index
Supported Environments
- Node.js: 18.x, 19.x
- Deno: 1.x
Installation
Web Browser
Followings are how to use with typical CDNs. Other CDNs can be used as well.
Using esm.sh:
<!-- use a specific version -->
<script type="module">
import * as bhttp from "https://esm.sh/bhttp-js@0.1.1";
// ...
</script>
<!-- use the latest stable version -->
<script type="module">
import * as bhttp from "https://esm.sh/bhttp-js";
// ...
</script>
Using unpkg:
<!-- use a specific version -->
<script type="module">
import * as bhttp from "https://unpkg.com/bhttp-js@0.1.1/esm/mod.js";
// ...
</script>
Node.js
Using npm:
npm install bhttp-js
Using yarn:
yarn add bhttp-js
Deno
Using deno.land:
// use a specific version
import * as bhttp from "https://deno.land/x/bhttp@v0.1.1/mod.ts";
// use the latest stable version
import * as bhttp from "https://deno.land/x/bhttp/mod.ts";
Usage
This section shows some typical usage examples.
Node.js
const { BHttpEncoder, BHttpDecoder } = require("bhttp-js");
async function doBHttp() {
const req = new Request("https://www.example.com/hello.txt", {
method: "GET",
headers: {
"User-Agent": "curl/7.16.3 libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3",
"Accept-Language": "en, mi",
},
});
// Encode a Request object to a BHTTP binary string.
const encoder = new BHttpEncoder();
const binReq = await encoder.encodeRequest(req);
// Decode the BHTTP binary string to a Request object.
const decoder = new BHttpDecoder();
const decodedReq = decoder.decodeRequest(binReq);
}
doBHttp();
Deno
import {
BHttpDecoder,
BHttpEncoder,
} from "https://deno.land/x/bhttp@v0.1.1/mod.ts";
const req = new Request("https://www.example.com/hello.txt", {
method: "GET",
headers: {
"User-Agent": "curl/7.16.3 libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3",
"Accept-Language": "en, mi",
},
});
// Encode a Request object to a BHTTP binary string.
const encoder = new BHttpEncoder();
const binReq = await encoder.encodeRequest(req);
// Decode the BHTTP binary string to a Request object.
const decoder = new BHttpDecoder();
const decodedReq = decoder.decodeRequest(binReq);
Contributing
We welcome all kind of contributions, filing issues, suggesting new features or sending PRs.