developmentseed/hapi-paginate

语言: JavaScript

git: https://github.com/developmentseed/hapi-paginate

对于hapijs响应的简单分页
A simple pagination for hapijs responses
README.md (中文)

生日快乐

npm version
Build Status

Hapi的基本分页插件。

该插件侦听页面并限制查询参数并将它们添加到请求对象。

Hapi应用程序应该决定如何处理request.page和request.limit值。

然后,插件将一个元键添加到输出json响应,并在结果键下移动响应。

要将插件限制为特定路由,请将路由添加到选项。

curl -X GET http://www.example.com?page=3&limit=100

{
    "meta": {
        "page": 3,
        "limit": 100
    },
    "results": {
        "key": "value"
    }
}

安装

$: npm install hapi-paginate

注册

var Hapi = require('hapi');

var hapi = new Hapi.Server();
hapi.connection();

hapi.register({
  register: require('hapi-paginate'),
  options: {
    limit: 1000,
    name: 'My Meta',
    results: 'output',
    routes: ['/', '/api']
  }
};

测试

$ npm test

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

hapi-paginate

npm version
Build Status

A basic pagination plugin for Hapi.

The plugin listens to page and limit query parameters and add them to request object.

The Hapi app should decide how to handle request.page and request.limit values.

The plugin then adds a meta key to the output json response and move the response under results key.

To limit the plugin to specific routes, adds routes to options.

Example

curl -X GET http://www.example.com?page=3&limit=100

{
    "meta": {
        "page": 3,
        "limit": 100
    },
    "results": {
        "key": "value"
    }
}

Installation

$: npm install hapi-paginate

Registration

var Hapi = require('hapi');

var hapi = new Hapi.Server();
hapi.connection();

hapi.register({
  register: require('hapi-paginate'),
  options: {
    limit: 1000,
    name: 'My Meta',
    results: 'output',
    routes: ['/', '/api']
  }
};

Test

$ npm test