pil
Koa middleware for setting rules HTTP method parameters to endpoints. Make parameter validation as easy-as-pil
npm install pil
pil.set({opts})
Set parameter options;
Key | Type | Description |
---|---|---|
name | String | Name of your parameter, you must include this in your options. |
required | Boolean | Required if true, optional if false - true by default. |
regex | Object (regex) | A regular expression to match with if parameter is string. |
type | String | Parameter data type; boolean - number - string - object - array. |
error | Object | Set custom error messages in specific scenarios. |
Quickstart
Here is an example application using pil to set parameters we want, we can be sure we will receive parameters in request.params
as pil handles everything else.
'use strict'; let koa = mount = Router = bodyParser = pil = app = app let test = app test app
Check examples in test/ folder in both app.js for pure koa application using pil or rapp.js for routed app example like this quickstart.
-
Must be running node with
v4.3.*
or higher -
For POST / PUT methods pil works with works with the official
koa-bodyparser
best or other body parsing libraries which set data tothis.request.body
. This libraries will extend to support pure koa post requests.
Authors; Ulpian Morina