fetch-link-util
Version:
helper to extract fetch link header values (paging/RFC-8288)
68 lines (45 loc) • 2.94 kB
Markdown
[](https://www.npmjs.com/package/fetch-link-util)
[](https://spdx.org/licenses/0BSD.html)
[](https://typescriptlang.org)
[](https://bundlejs.com/?q=fetch-link-util)
[](https://npmjs.org/package/fetch-link-util)
[](https://github.com/arlac77/fetch-link-util/issues)
[](https://actions-badge.atrox.dev/arlac77/fetch-link-util/goto)
[](https://github.com/prettier/prettier)
[](http://commitizen.github.io/cz-cli/)
[](https://snyk.io/test/github/arlac77/fetch-link-util)
[](https://coveralls.io/github/arlac77/fetch-link-util)
# fetch-link-util
helper to extract fetch link header values (https://datatracker.ietf.org/doc/html/rfc8288)
# Example
```js
import { getHeaderLink } from "fetch-link-util";
async listAllBranches() {
let next = "https://api.github.com/repos/arlac77/fetch-link-util/branches";
do {
const response = await fetch(next);
const json = await response.json();
console.log(json.map(branch => branch.name));
next = getHeaderLink(response.headers);
} while (next);
}
```
# API
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
* [getHeaderLink](#getheaderlink)
* [Parameters](#parameters)
## getHeaderLink
* **See**: <https://datatracker.ietf.org/doc/html/rfc8288>
Decodes link header and delivers one href entry.
### Parameters
* `headers` **[Headers](https://developer.mozilla.org/docs/Web/HTML/Element/header)** as given by fetch response
* `rel` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** of link to retrieve (optional, default `"next"`)
Returns **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** href for given rel
# install
With [npm](http://npmjs.org) do:
```shell
npm install fetch-link-util
```
# license
BSD-2-Clause