11# hapi-pagination
22
3- [ ![ Greenkeeper badge] ( https://badges.greenkeeper.io/fknop/hapi-pagination.svg )] ( https://greenkeeper.io/ )
4-
53[ ![ NPM Version] ( https://img.shields.io/npm/v/hapi-pagination.svg )] ( https://npmjs.org/package/hapi-pagination )
64[ ![ Build Status] ( https://travis-ci.org/fknop/hapi-pagination.svg )] ( https://travis-ci.org/fknop/hapi-pagination )
75[ ![ Coverage Status] ( https://coveralls.io/repos/fknop/hapi-pagination/badge.svg?branch=master&service=github )] ( https://coveralls.io/github/fknop/hapi-pagination?branch=master )
@@ -15,6 +13,10 @@ Hapi plugin to handle 'custom' resources pagination in json only.
1513npm install hapi-pagination --save
1614```
1715
16+ ## Version 2.0.0
17+
18+ Version 2.0.0 is intended for use with Hapi 1.17.x and above, do not use this version for version below 1.17.x of hapi.
19+
1820## Contribute
1921
2022Post an issue if you encounter a bug or an error in the documentation.
@@ -139,15 +141,16 @@ config: {
139141}
140142```
141143
142- #### reply .paginate(Array|Object, [ totalCount] , [ options = {}] )
144+ #### h .paginate(Array|Object, [ totalCount] , [ options = {}] )
143145
144146The method is an helper method. This is a shortcut for:
145147
146148``` javascript
147- reply ({results: results, totalCount: totalCount});
149+ h . response ({results: results, totalCount: totalCount});
148150```
149151
150152You can change names of fields (` results ` , ` totalCount ` ) using reply options.
153+
151154```
152155reply: {
153156 results: {
@@ -164,7 +167,7 @@ You can also reply the array and set the totalCount by adding the totalCount
164167
165168```
166169request.totalCount = 10;
167- reply (results);
170+ h.response (results);
168171```
169172
170173The ` paginate ` method also offers a way to add custom properties to your response. You just have to
@@ -173,7 +176,7 @@ pass an object as first parameter and pass a `options.key` parameter which is th
173176For example:
174177
175178```
176- return reply .paginate({ results: [], otherKey: 'value', otherKey2: 'value2' }, 0, { key: 'results' });
179+ return h .paginate({ results: [], otherKey: 'value', otherKey2: 'value2' }, 0, { key: 'results' });
177180```
178181
179182The response will also contains ` otherKey ` and ` otherKey2 ` . Nested keys for the paginated results are not allowed.
@@ -185,7 +188,7 @@ Please note that if you pass metadata in headers the custom properties don't wor
185188##### WARNING: If the results is not an array, the program will throw an implementation error.
186189
187190If totalCount is not exposed through the request object
188- or the reply .paginate method, the following attributes will be
191+ or the h .paginate method, the following attributes will be
189192set to null if they are active.
190193 * ` last `
191194 * ` pageCount `
@@ -296,22 +299,19 @@ const options = {
296299``` javascript
297300const Hapi = require (' hapi' );
298301
299- let server = new Hapi.Server ();
302+ const server = new Hapi.Server ();
300303
301304// Add your connection
302305
303- server .register (require (' hapi-pagination' ), (err ) => {
304- if (err)
305- throw err;
306- });
306+ await server .register (require (' hapi-pagination' ))
307307```
308308
309309### Example with options
310310
311311``` javascript
312312const Hapi = require (' hapi' );
313313
314- let server = new Hapi.Server ();
314+ const server = new Hapi.Server ();
315315
316316// Add your connection
317317
@@ -350,11 +350,7 @@ const options = {
350350 }
351351};
352352
353- server .register ({register: require (' hapi-pagination' ), options: options}, (err)
354- => {
355- if (err)
356- throw err;
357- });
353+ await server .register ({plugin: require (' hapi-pagination' ), options: options})
358354```
359355### Disable globally and activate pagination on specific routes
360356
@@ -363,7 +359,7 @@ Global configuration:
363359``` javascript
364360const Hapi = require (' hapi' );
365361
366- let server = new Hapi.Server ();
362+ const server = new Hapi.Server ();
367363
368364// Add your connection
369365
@@ -374,11 +370,7 @@ const options = {
374370 }
375371};
376372
377- server .register ({register: require (' hapi-pagination' ), options: options}, (err)
378- => {
379- if (err)
380- throw err;
381- });
373+ await server .register ({plugin: require (' hapi-pagination' ), options: options})
382374```
383375Activate on route level:
384376
0 commit comments