koa-qs-lru
v1.0.0
Published
Nested query string support for Koa using LRU cache.
Downloads
4
Readme
Koa Query String LRU
By default, Koa uses the native querystring
module which does not provide nesting support and caches parsed results in a plain object regardless of his size.
This pathes a Koa app with:
- qs (a querystring parsing and stringifying library with some added security)
- lru-cache (a cache object that deletes the least-recently-used items)
Installation
$ npm install --save koa-qs-lru
Usage
var koa = require('koa')
var qs = require('koa-qs-lru');
// qs & lru-cache default settings
var app = qs(koa());
// custom settings
var app = qs(koa(), {
cache: {}, // lru-cache options
parse: {}, // qs -> parse options
stringify: {} // qs -> stringify options
});
Check qs and lru-cache packages for API documentation.
Example
var koa = require('koa')
var qs = require('koa-qs-lru');
var app = qs(koa(), {
cache: { max: 1000 }, // Keep last 1000 used query objects in cache
parse: { parameterLimit: 1 } // Parse only the first parameter
});
app.use(function *() {
this.body = this.query;
});
app.listen(3000);