An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

[![npm](https://img.shields.io/npm/v/fetch-link-util.svg)](https://www.npmjs.com/package/fetch-link-util)
[![License](https://img.shields.io/badge/License-0BSD-blue.svg)](https://spdx.org/licenses/0BSD.html)
[![Typed with TypeScript](https://flat.badgen.net/badge/icon/Typed?icon=typescript\&label\&labelColor=blue\&color=555555)](https://typescriptlang.org)
[![bundlejs](https://deno.bundlejs.com/?q=fetch-link-util\&badge=detailed)](https://bundlejs.com/?q=fetch-link-util)
[![downloads](http://img.shields.io/npm/dm/fetch-link-util.svg?style=flat-square)](https://npmjs.org/package/fetch-link-util)
[![GitHub Issues](https://img.shields.io/github/issues/arlac77/fetch-link-util.svg?style=flat-square)](https://github.com/arlac77/fetch-link-util/issues)
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Farlac77%2Ffetch-link-util%2Fbadge\&style=flat)](https://actions-badge.atrox.dev/arlac77/fetch-link-util/goto)
[![Styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Known Vulnerabilities](https://snyk.io/test/github/arlac77/fetch-link-util/badge.svg)](https://snyk.io/test/github/arlac77/fetch-link-util)
[![Coverage Status](https://coveralls.io/repos/arlac77/fetch-link-util/badge.svg)](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