{"id":16067,"library":"http-link-header","title":"HTTP Link Header Parser & Formatter","description":"http-link-header is a JavaScript library designed for parsing and formatting HTTP Link headers as defined by RFC 8288 (which supersedes RFC 5988). The current stable version is 1.1.3, last published in 2018, indicating a low or absent release cadence. A key characteristic is its explicit deviation from RFC 8288 regarding relative URI-References: the library does *not* automatically resolve them, leaving this responsibility to the user. This design choice is critical for developers to be aware of, as it means the parsed URIs might not be absolute without further processing. The library provides methods for parsing single or multiple headers, checking for specific references, retrieving references by attribute, and setting/uniquely setting new references, along with stringifying Link objects back into HTTP header format.","status":"abandoned","version":"1.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/jhermsmeier/node-http-link-header","tags":["javascript","rfc5988","rfc8288","rfc","5988","8288","http","link","header"],"install":[{"cmd":"npm install http-link-header","lang":"bash","label":"npm"},{"cmd":"yarn add http-link-header","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-link-header","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is a CommonJS module. Direct ES module `import` statements may not work as expected in modern environments without specific bundler configuration.","wrong":"import LinkHeader from 'http-link-header';\nimport { LinkHeader } from 'http-link-header';","symbol":"LinkHeader (main class)","correct":"const LinkHeader = require('http-link-header');"},{"note":"The `parse` method is a static method of the `LinkHeader` class, not a direct named export from the package.","wrong":"import { parse } from 'http-link-header';","symbol":"LinkHeader.parse (static method)","correct":"const LinkHeader = require('http-link-header');\nconst link = LinkHeader.parse(headerString);"},{"note":"To create a new, empty `Link` object for accumulating or building headers, instantiate the `LinkHeader` class. The instance methods like `set` and `setUnique` operate on this object.","wrong":"import { Link } from 'http-link-header';\nimport Link from 'http-link-header';","symbol":"Link (instance)","correct":"const LinkHeader = require('http-link-header');\nconst link = new LinkHeader();"}],"quickstart":{"code":"const LinkHeader = require('http-link-header');\n\n// Example HTTP Link header string with multiple relations and extended attributes\nconst headerString = '<https://example.com/next>; rel=\"next\", ' +\n                     '<https://example.com/prev>; rel=\"prev\"; title=\"Previous Page\", ' +\n                     '<https://example.com/image.png>; rel=\"preload\"; as=\"image\"; type=\"image/png\", ' +\n                     '</extended-attr-example>; rel=start; title*=UTF-8\\'en\\'%E2%91%A0%E2%93%AB%E2%85%93%E3%8F%A8%E2%99%B3%F0%9D%84%9E%CE%BB';\n\n// Parse the header string\nconst link = LinkHeader.parse(headerString);\n\nconsole.log('Parsed Link Header:', JSON.stringify(link, null, 2));\nconsole.log('First reference URI:', link.refs[0].uri);\nconsole.log('All \"prev\" references:', link.rel('prev'));\nconsole.log('Extended title value:', link.get('rel', 'start')[0]['title*'].value);\n\n// Add a new unique reference\nlink.setUnique({\n  uri: 'https://example.com/canonical',\n  rel: 'canonical'\n});\nconsole.log('\\nAfter adding canonical:', JSON.stringify(link.refs, null, 2));\n\n// Stringify back to header format\nconst formattedHeader = link.toString();\nconsole.log('\\nFormatted Header:', formattedHeader);\n\n// Check for a specific relation\nconsole.log('\\nHas \"preload\" relation?', link.has('rel', 'preload'));","lang":"javascript","description":"Demonstrates parsing a complex HTTP Link header string (including extended attributes), accessing individual references, filtering by relation type, adding new unique references, and stringifying the Link object back to a header format."},"warnings":[{"fix":"Implement custom URI resolution logic using a base URI after parsing the Link header. For example, `new URL(link.refs[0].uri, baseUrl).toString()`.","message":"This library explicitly deviates from RFC 8288 by not automatically resolving relative URI-References. Parsed URIs remain relative and must be resolved by the user's application if absolute URIs are required.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `const LinkHeader = require('http-link-header');` for CommonJS environments. In ES module contexts, consider using a bundler (e.g., Webpack, Rollup) or evaluate alternatives that offer native ESM support.","message":"The `http-link-header` package is a CommonJS module and does not provide native ES Module (`import`) exports. Using `import` statements directly in modern Node.js or browser environments may lead to unexpected behavior or require bundler configuration.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Evaluate if this library meets your long-term needs. For new projects or critical applications, consider alternatives like `@hugoalh/http-header-link` (which supports ESM/TypeScript) or be prepared to fork and maintain the package yourself.","message":"The `http-link-header` package appears to be unmaintained, with its last release in 2018. While functional for its stated purpose, users should be aware of the lack of ongoing bug fixes, security updates, or feature development. Consider newer alternatives for active projects.","severity":"deprecated","affected_versions":">=1.1.3"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Change your import statement to `const LinkHeader = require('http-link-header');` or configure your TypeScript/bundler setup to handle CommonJS modules.","cause":"Attempting to use ES module import syntax for a CommonJS module in a TypeScript or ES module environment, where the default export is not correctly resolved.","error":"TypeError: http_link_header_1.LinkHeader is not a constructor"},{"fix":"Ensure you are using `const LinkHeader = require('http-link-header');` to get the correct CommonJS module export that exposes the `parse` static method.","cause":"Similar to the constructor error, this occurs when the `LinkHeader` object obtained via `import` is not the expected class or lacks the static `parse` method due to incorrect CommonJS/ESM interop.","error":"TypeError: LinkHeader.parse is not a function"},{"fix":"After parsing, manually resolve relative URIs against a known base URL (e.g., the URL of the document that returned the Link header) using `new URL(relativeUri, baseUrl).href`.","cause":"The library does not resolve relative URIs in Link headers, leading to downstream errors if subsequent code expects absolute URLs.","error":"Error: Invalid or relative URI passed to further processing logic"}],"ecosystem":"npm"}