https://github.com/blockloop/weblinks.js
Create pagination links for REST endpoints in accordance with RFC5988
https://github.com/blockloop/weblinks.js
Last synced: about 2 months ago
JSON representation
Create pagination links for REST endpoints in accordance with RFC5988
- Host: GitHub
- URL: https://github.com/blockloop/weblinks.js
- Owner: blockloop
- Created: 2016-09-27T20:21:36.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-28T01:31:30.000Z (over 9 years ago)
- Last Synced: 2025-10-05T02:53:31.718Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Weblinks for javascript
This project creates pagination links for REST endpoints in accordance with [RFC5988](https://tools.ietf.org/html/rfc5988).
## Install
```bash
npm install --save weblinks
```
## Usage
### Create
```javascript
const weblinks = require("weblinks");
weblinks.create("http://website.com", 2 /*page*/, 10 /*pageCount*/, 100 /*totalCount*/);
{ url: 'http://website.com',
self:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'website.com',
port: null,
hostname: 'website.com',
hash: null,
query: { page: 2, page_size: 10 },
pathname: '/',
path: '/',
href: 'http://website.com/',
toString: [Function] },
first:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'website.com',
port: null,
hostname: 'website.com',
hash: null,
query: { page: 1, page_size: 10 },
pathname: '/',
path: '/',
href: 'http://website.com/',
toString: [Function] },
last:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'website.com',
port: null,
hostname: 'website.com',
hash: null,
query: { page: 10, page_size: 10 },
pathname: '/',
path: '/',
href: 'http://website.com/',
toString: [Function] },
prev:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'website.com',
port: null,
hostname: 'website.com',
hash: null,
query: { page: 1, page_size: 10 },
pathname: '/',
path: '/',
href: 'http://website.com/',
toString: [Function] },
next:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'website.com',
port: null,
hostname: 'website.com',
hash: null,
query: { page: 3, page_size: 10 },
pathname: '/',
path: '/',
href: 'http://website.com/',
toString: [Function] },
linkHeader: `; rel="self",
; rel="first",
; rel="last",
; rel="next",
; rel="prev"` }
```
### Parse Header
```javascript
const weblinks = require("weblinks");
const header = `; rel="self",
; rel="first",
; rel="last",
; rel="next",
; rel="prev"`;
{ url: 'http://website.com',
self:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'website.com',
port: null,
hostname: 'website.com',
hash: null,
query: { page: 2, page_size: 10 },
pathname: '/',
path: '/',
href: 'http://website.com/',
toString: [Function] },
first:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'website.com',
port: null,
hostname: 'website.com',
hash: null,
query: { page: 1, page_size: 10 },
pathname: '/',
path: '/',
href: 'http://website.com/',
toString: [Function] },
last:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'website.com',
port: null,
hostname: 'website.com',
hash: null,
query: { page: 10, page_size: 10 },
pathname: '/',
path: '/',
href: 'http://website.com/',
toString: [Function] },
prev:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'website.com',
port: null,
hostname: 'website.com',
hash: null,
query: { page: 1, page_size: 10 },
pathname: '/',
path: '/',
href: 'http://website.com/',
toString: [Function] },
next:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'website.com',
port: null,
hostname: 'website.com',
hash: null,
query: { page: 3, page_size: 10 },
pathname: '/',
path: '/',
href: 'http://website.com/',
toString: [Function] } }