Link Header Parser

0.1.2 · active · verified Sun Apr 19

This package, `linkheader-parser` (version 0.1.2), offers a minimalist utility for parsing HTTP `Link` headers as defined in RFC 5988. Given its very early stage versioning, it is likely in an experimental or pre-1.0 development phase, meaning the API might not yet be stable and releases are infrequent. Its core function is to extract structured information (like URI, relation types, and parameters) from a standard `Link` header string. As a focused parser, its key differentiator is its lightweight implementation and direct adherence to the RFC, without additional features like URI resolution. Users should be aware that such an early version implies potential for breaking changes in minor releases and limited support compared to more mature alternatives. It is a simple, no-dependency parser for web linking metadata.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to parse a complex RFC 5988 Link header string and access the extracted link information.

import { parse } from 'linkheader-parser';

const linkHeaderString = '<https://example.com/api/page/2>; rel="next", ' +
                         '<https://example.com/api/page/1>; rel="prev", ' +
                         '<https://example.com/api/page/last>; rel="last"; title="Last Page"; type="text/html"; param_with_dashes="value-here"';

try {
  const parsedLinks = parse(linkHeaderString);
  console.log('Parsed "next" link:', parsedLinks.next);
  console.log('Parsed "last" link URI:', parsedLinks.last?.uri);
  console.log('All parsed links:', JSON.stringify(parsedLinks, null, 2));
} catch (error) {
  console.error('Error parsing link header:', error.message);
}

// Expected output structure (example, actual depends on library implementation):
// {
//   next: { uri: 'https://example.com/api/page/2', rel: 'next' },
//   prev: { uri: 'https://example.com/api/page/1', rel: 'prev' },
//   last: { uri: 'https://example.com/api/page/last', rel: 'last', title: 'Last Page', type: 'text/html', 'param_with_dashes': 'value-here' }
// }

view raw JSON →