Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-link-header

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-link-header

Parse & format HTTP link headers according to RFC 8288

  • 1.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
939K
decreased by-14%
Maintainers
1
Weekly downloads
 
Created

What is http-link-header?

The http-link-header npm package is used to parse and construct HTTP Link headers. It provides a convenient way to handle the Link header, which is used in HTTP responses to provide metadata about the requested resource, such as pagination links, relationships, and more.

What are http-link-header's main functionalities?

Parsing Link Headers

This feature allows you to parse a Link header string into an object. The parsed object contains references (refs) that you can easily access and manipulate.

const LinkHeader = require('http-link-header');
const linkHeader = LinkHeader.parse('<https://api.example.com/users?page=2>; rel="next", <https://api.example.com/users?page=5>; rel="last"');
console.log(linkHeader.refs);

Constructing Link Headers

This feature allows you to construct a Link header string from an object. You can add multiple links with different relations and then convert the object back to a string format suitable for HTTP headers.

const LinkHeader = require('http-link-header');
const linkHeader = new LinkHeader();
linkHeader.set({
  uri: 'https://api.example.com/users?page=2',
  rel: 'next'
});
linkHeader.set({
  uri: 'https://api.example.com/users?page=5',
  rel: 'last'
});
console.log(linkHeader.toString());

Finding Links by Relation

This feature allows you to find a specific link by its relation type (rel). This is useful for quickly accessing specific links like 'next', 'prev', 'first', or 'last' in paginated responses.

const LinkHeader = require('http-link-header');
const linkHeader = LinkHeader.parse('<https://api.example.com/users?page=2>; rel="next", <https://api.example.com/users?page=5>; rel="last"');
const nextLink = linkHeader.get('rel', 'next');
console.log(nextLink);

Other packages similar to http-link-header

Keywords

FAQs

Package last updated on 16 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc