在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:uphold/koa-pagination开源软件地址:https://github.com/uphold/koa-pagination开源编程语言:JavaScript 100.0%开源软件介绍:koa-pagination
StatusInstallationInstall the package via ❯ yarn add koa-pagination or via ❯ npm install koa-pagination --save ConfigurationThe middleware can be configured with the following parameters:
You can change the defaults by doing: middleware({
allowAll: true,
maximum: 100,
unit: 'bytes'
}); Usageconst { middleware } = require('koa-pagination');
const Koa = require('koa');
const app = new Koa();
app.get('/', middleware(), async ctx => {
// `paginate` middleware will inject a `pagination` object in the `koa` context,
// which will allow you to use the `pagination.offset` and `pagination.limit`
// in your data retrieval methods.
ctx.body = await foobar.getData({
limit: ctx.pagination.limit,
offset: ctx.pagination.offset
});
// This is needed in order to expose the length in `Content-Range` header.
ctx.pagination.length = foobar.count();
});
app.listen(3000); RequestYou can provide the 'Range: items=0-4' You can also provide 'Range: items=0-*' ResponseThe first example will generate a response with the following headers: 'Accepted-Ranges': 'items'
'Content-Range: items 0-4/*' The Codes
Tests❯ yarn test Release❯ npm version [<new version> | major | minor | patch] -m "Release %s" |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论