Skip to content

spider-gazelle/link-header

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crystal Lang HTTP Link Header Parser

CI

Parses link headers

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      link-header:
        github: spider-gazelle/link-header
  2. Run shards install

Usage

require "http/client"
require "link-header"

# Parse the links out of the response
response = HTTP::Client.get "http://www.example.com"
links = LinkHeader.new(response)

# equivalent to the above
links = LinkHeader.new(response.headers)

# Get the first link matching a `rel`
links["next"] # => "https://next.link/"  or raise KeyError
links["next"]? # => "https://next.link/" or nil

# Get all the links matching a `rel`
links.get("preconnect") # => ["https://link.1/", "https://link.2/"]
links.get("missing") # => []