Parse rfc5988 style pagination Link headers from a fetch
Response
object.
npm install header-pagination
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}
})
Given a fetch
Response
, returns an object with the following properties:
{
last,
next,
prev,
first,
current,
total // if X-Total-Count is included
}
- netlify/micro-api-client: Extracted from netlify's Micro-api-client.
- developer.github.com/v3/#pagination: Github style pagination.
- rfc5988-section 5: Spec describing the use of
Link rel=
headers.
MIT