Skip to content

mjankowski/link_header

 
 

Repository files navigation

Link Header

Parse and format HTTP link headers (and equivalent HTML link elements) as described in the Web Linking spec.

Description

Converts conforming link headers or HTML link elements to and from text, LinkHeader objects and corresponding (JSON-friendly) Array representations.

Installation

bundle add link_header

Usage

require "link_header"

http_link_header = <<~HEADER
  <https://example.com/foo>; rel="self", <https://example.com/>; rel = "up"
HEADER

LinkHeader
  .parse(http_link_header)
  .to_a
#=> [["https://example.com/foo", [["rel", "self"]]], ["https://example.com/", [["rel", "up"]]]]

link_header = LinkHeader.new([
    ["https://example.com/foo", [%w[rel self]]],
    ["https://example.com/", [%w[rel up]]]
])

link_header.to_s
#=> '<https://example.com/foo>; rel="self", <https://example.com/>; rel="up"'

link_header.to_html
#=> '<link href="https://example.com/foo" rel="self">
#    <link href="https://example.com/" rel="up">'

For more see the LinkHeader and LinkHeader::Link classes or example.rb.

Author

Mike Burrows (asplake), email [email protected], website positiveincline.com.

About

In Ruby, parse and format HTTP link headers as described in the draft spec https://tools.ietf.org/id/draft-nottingham-http-link-header-06.txt

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%