Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spider-gazelle/link-header
Crystal Lang HTTP Link Header Parser
https://github.com/spider-gazelle/link-header
Last synced: about 1 month ago
JSON representation
Crystal Lang HTTP Link Header Parser
- Host: GitHub
- URL: https://github.com/spider-gazelle/link-header
- Owner: spider-gazelle
- License: mit
- Created: 2020-09-30T00:13:46.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-26T00:40:22.000Z (over 3 years ago)
- Last Synced: 2024-11-18T22:32:21.276Z (2 months ago)
- Language: Crystal
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - link-header - HTTP Link Header Parser (HTTP)
README
# Crystal Lang HTTP Link Header Parser
[![CI](https://github.com/spider-gazelle/link-header/actions/workflows/ci.yml/badge.svg)](https://github.com/spider-gazelle/link-header/actions/workflows/ci.yml)
Parses link headers
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
link-header:
github: spider-gazelle/link-header
```2. Run `shards install`
## Usage
```crystal
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") # => []```