Skip to content

Parse rfc5988 style pagination Link headers from a fetch Response object.

License

Notifications You must be signed in to change notification settings

bcomnes/header-pagination

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

header-pagination

Actions Status

Parse rfc5988 style pagination Link headers from a fetch Response object.

npm install header-pagination

Usage

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 Response, returns an object with the following properties:

{
  last,
  next,
  prev,
  first,
  current,
  total // if X-Total-Count is included
}

See also

License

MIT

About

Parse rfc5988 style pagination Link headers from a fetch Response object.

Resources

License

Stars

Watchers

Forks

Packages

No packages published