JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 199
  • Score
    100M100P100Q82706F
  • License MIT

A BHTTP (Binary Representation of HTTP Messages) Encoder and Decoder

Package Exports

  • bhttp-js
  • bhttp-js/package.json

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bhttp-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

bhttp-js

deno doc Node.js CI Deno CI codecov

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

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.0";
  // ...
</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.0/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@0.1.0/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@0.1.0/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.

References