Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bcomnes/header-pagination
Parse rfc5988 style pagination Link headers from a fetch Response object.
https://github.com/bcomnes/header-pagination
Last synced: 5 days ago
JSON representation
Parse rfc5988 style pagination Link headers from a fetch Response object.
- Host: GitHub
- URL: https://github.com/bcomnes/header-pagination
- Owner: bcomnes
- License: mit
- Created: 2019-11-19T17:57:34.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-10T14:31:37.000Z (4 months ago)
- Last Synced: 2024-11-01T18:42:24.506Z (12 days ago)
- Language: JavaScript
- Homepage: https://npmjs.com/header-pagination
- Size: 80.1 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/funding.yml
- License: LICENSE
Awesome Lists containing this project
README
# header-pagination
[![Actions Status](https://github.com/bcomnes/header-pagination/workflows/tests/badge.svg)](https://github.com/bcomnes/header-pagination/actions)Parse rfc5988 style pagination Link headers from a [`fetch`][fetch] [`Response`][response] object.
```
npm install header-pagination
```## Usage
``` js
import { getPagination } from 'header-pagination'window.fetch(req).then(async response => {
const pagination = getPagination(response.headers)
// {
// last,
// next,
// prev,
// first,
// current,
// total (if X-Total-Count is included)
// }
const json = await response.json()
return {pagination, json}
})
```## API
### `getPagination(response)`
Given a [`fetch`][fetch] [`Response`][response], returns an object with the following properties:
```js
{
last,
next,
prev,
first,
current,
total // if X-Total-Count is included
}
```## See also
- [netlify/micro-api-client](https://github.com/netlify/micro-api-client): Extracted from netlify's Micro-api-client.
- [developer.github.com/v3/#pagination](https://developer.github.com/v3/#pagination): Github style pagination.
- [rfc5988-section 5][rfc5988]: Spec describing the use of `Link rel=` headers.## License
MIT
[response]: https://developer.mozilla.org/en-US/docs/Web/API/Response
[fetch]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
[rfc5988]: https://tools.ietf.org/html/rfc5988#section-5