Kless
A MVC framework inspired by FaaS, based on koa
.
Installation
$ npm i @nswbmw/kless --save
Scaffold
see create-kless-app.
Example
simple
const Kless = const app = app app /*$ curl localhost:3000/User.getUserById?id=123123*/
complex
const Kless = const app = app app app app /*$ curl localhost:3000/User.getUserById?id=123{"uid":"123","name":1547619443338,"age":18}*/
Validator
const Kless = const app = app app /*$ curl localhost:3000/User.getUserById($.query.id: undefined) ✖ (required: true)$ curl localhost:3000/User.getUserById?id=test($.query.id: "test") ✖ (type: Number)$ curl localhost:3000/User.getUserById?id=123123*/
More validators usage see another-json-schema.
Array controllers
const bodyParser = const Kless = const app = app app
API
app.middleware(name, fn) app.middleware(name, obj)
- name(String): middleware name.
- fn(Function)|obj(Object): middleware function or object.
app.route(obj)
- name(String): route name, mapping to a router, eg: User.createUser -> /User.createUser.
- controller(Function|AsyncFunction|[Function|AsyncFunction]): router controller.
app.controller(name, fn) app.controller(name, obj)
- name(String): controller name.
- fn(Function)|obj(Object): controller function or object.
app.service(name, fn) app.service(name, obj)
- name(String): service name.
- fn(Function)|obj(Object): service function or object.
NB: When use object as service's second parameter, you can use this
in function that reference to obj
.
Test
$ npm test
License
MIT