This is a Deno module for parsing HTTP Link headers.
Yes, there are already a number of Node.js packages for parsing link headers; this module was mostly an excuse for me to try Deno and learn a little about a somewhat obscure HTTP header.
Use in Deno:
import { parseLinkHeader } from "https://cdn.jsdelivr.net/gh/bryik/deno-parse-link-header@v0.1.1/parseLinkHeader.ts";
const example = `<https://example.com>; msg1="preconnect" msg2=hello`;
const parsedLinkHeader = parseLinkHeader(example);
console.log(parsedLinkHeader);
// [{uri: "https://example.com", msg1: "preconnect", msg2: "hello"}]
Use in browser (import the ES Module /dist/parseLinkHeader.bundle.js
):
<script type="module">
import { parseLinkHeader } from "https://cdn.jsdelivr.net/gh/bryik/deno-parse-link-header@v0.1.1/dist/parseLinkHeader.bundle.js";
const linkHeader = `<https://example.com>; msg1="preconnect" msg2="hello"`;
console.log(parseLinkHeader(linkHeader));
// [{uri: "https://example.com", msg1: "preconnect", msg2: "hello"}]
</script>
First clone this repo and cd
into it. You will need to have deno installed.
deno cache --reload --lock=lock.json ./deps.ts
deno cache --lock=lock.json --lock-write ./deps.ts
deno test
deno bundle ./parseLinkHeader.ts ./dist/parseLinkHeader.bundle.js
-
MDN's article on Link headers provides a concise description of what a Link header is.
-
thlorenz' parse-link-header node package was a useful reference and I re-used many of his test cases.
-
Section 3 of RFC 8288 is the definitive specification for Link headers. It is very dry.