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

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

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] } }