https://github.com/arlac77/fetch-link-util
helper to extract fetch link header values
https://github.com/arlac77/fetch-link-util
fetch paging
Last synced: about 1 year ago
JSON representation
helper to extract fetch link header values
- Host: GitHub
- URL: https://github.com/arlac77/fetch-link-util
- Owner: arlac77
- License: 0bsd
- Created: 2020-06-18T11:41:07.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-04-06T00:06:19.000Z (about 1 year ago)
- Last Synced: 2025-04-06T00:24:16.571Z (about 1 year ago)
- Topics: fetch, paging
- Language: JavaScript
- Homepage:
- Size: 2.53 MB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](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
### Table of Contents
* [getHeaderLink](#getheaderlink)
* [Parameters](#parameters)
## getHeaderLink
* **See**:
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