PHPackages                             goedemiddag/link-header-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. goedemiddag/link-header-parser

ActiveLibrary[HTTP &amp; Networking](/categories/http)

goedemiddag/link-header-parser
==============================

Package for parsing the Link HTTP header

v1.0.0(1mo ago)162↓50%1MITPHPPHP ^8.3CI passing

Since May 9Pushed 1mo agoCompare

[ Source](https://github.com/goedemiddag/link-header-parser)[ Packagist](https://packagist.org/packages/goedemiddag/link-header-parser)[ Docs](https://github.com/goedemiddag/link-header-parser)[ RSS](/packages/goedemiddag-link-header-parser/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (1)

link-header-parser
==================

[](#link-header-parser)

A PHP package for parsing the HTTP `Link` header ([RFC 8288](https://www.rfc-editor.org/rfc/rfc8288)).

Requirements
------------

[](#requirements)

This package requires PHP 8.3+.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require goedemiddag/link-header-parser
```

Usage
-----

[](#usage)

Parse the link header with the `LinkHeaderFactory`, which will return a `LinkHeader` object.

```
use Goedemiddag\LinkHeaderParser\LinkHeaderFactory;

$header = 'Link: ; rel="next", ; rel="last"';

$linkHeader = LinkHeaderFactory::fromHeader($header);

$next = $linkHeader->getLink('next'); // Link object
$last = $linkHeader->getLink('last'); // Link object
$previous = $linkHeader->getLink('previous'); // null

echo $next->uri; // https://api.example.com/items?page=2
```

### Retrieving links by relation type

[](#retrieving-links-by-relation-type)

Use `getLink($rel)` to retrieve a `Link` object by its relation type. If the relation type is not found, it returns `null`.

```
$next = $linkHeader->getLink('next'); // Link object, or null
```

Note:

- `rel="Next"` and `rel="next"` both resolve via `getLink('next')`.
- When the same `rel` appears more than once, the last entry wins.

### Accessing link attributes

[](#accessing-link-attributes)

Each `Link` contains the URI, the rel and any optional extra parameters such as `type`, `title`, or `hreflang`.

```
$linkHeader = LinkHeaderFactory::fromHeader('; rel="alternate"; type="application/rss+xml"; title="RSS"');

$link = $linkHeader->getLink('alternate');

echo $link->uri; // https://example.com/feed
echo $link->rel; // alternate
echo $link->getAttribute('type'); // application/rss+xml
echo $link->getAttribute('title'); // RSS
echo $link->getAttribute('missing'); // null
```

There is also a `hasAttribute()` helper to check if the `Link` has an attribute:

```
$link->hasAttribute('type'); // true
$link->hasAttribute('missing'); // false
```

Note:

- Bare token parameters (e.g. `; nocache`) have no value and are silently ignored; only `name=value` pairs are stored as attributes.
- Attribute names are normalised to lowercase: `Type="text/html"` is accessible as `getAttribute('type')`.

### Example: GitHub pagination

[](#example-github-pagination)

```
// $response is a PSR-7 ResponseInterface
$linkHeaderValue = $response->getHeaderLine('Link');

$linkHeader = LinkHeaderFactory::fromHeader($linkHeaderValue);

$next = $linkHeader->getLink('next');
if ($next instanceof Link)
    // fetch $next->uri for the next page
}
```

Contributing
------------

[](#contributing)

Found a bug or want to add a new feature? Great! There are also many other ways to make meaningful contributions such as reviewing outstanding pull requests and writing documentation. Even opening an issue for a bug you found is appreciated.

When you create a pull request, make sure it is tested, following the code standard (run `composer code-style:fix` to take care of that for you) and please create one pull request per feature. In exchange, you will be credited as contributor.

### Testing

[](#testing)

To run the tests, you can use the following command:

```
composer test
```

### Security

[](#security)

If you discover any security related issues in this or other packages of Goedemiddag, please email instead of using the issue tracker.

About Goedemiddag
=================

[](#about-goedemiddag)

[Goedemiddag!](https://www.goedemiddag.nl) is a digital web-agency based in Delft, the Netherlands. We are a team of professionals who are passionate about the craft of building digital solutions that make a difference for its users. See our [GitHub organisation](https://github.com/goedemiddag) for more package.

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance94

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

31d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11698012?v=4)[Goedemiddag!](/maintainers/Goedemiddag)[@goedemiddag](https://github.com/goedemiddag)

---

Top Contributors

[![dvdheiden](https://avatars.githubusercontent.com/u/90568118?v=4)](https://github.com/dvdheiden "dvdheiden (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/goedemiddag-link-header-parser/health.svg)

```
[![Health](https://phpackages.com/badges/goedemiddag-link-header-parser/health.svg)](https://phpackages.com/packages/goedemiddag-link-header-parser)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25025.5M79](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

13137.2M6.4k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k20.0k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87930.4k112](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.3M82](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69122.6k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
