KambojaJs

NodeJS MVC Framework powered by TypeScript
API Convention
You don't need to decorate your classes or method to get clean API below:
GET /user/page/<offset>/<take>
GET /user/<id>
POST /user
{<payload body>}
PUT /user/<id>
{<payload body>}
DELETE /user/<id>
what you need todo is:
export class UserController : ApiController{
getByPage(offset, page){ }
get(id){ }
add(body){ }
modify(id, body){ }
delete(id){ }
}
Remember you are free to name your parameter KambojaJs will detect it for you.
Default Convention
For non API controller your method name will be the route
export class CarController : Controller{
getList(index, take){
return this.view()
}
}
With code above KambojaJs will generate
GET /car/getlist/:index/:take
Http Decorator
By default all action will be translated as HTTP GET, if you need
other method you need to add decorators
export class CarController : Controller{
@http.post()
save(body){
return this.json({success:true})
}
}
Code above will generate
POST /car/save
{<payload body>}
If you not happy with the generated route or you want a custom route
you can provide parameter on the http decorator
export class CarController : Controller{
@http.post("/garage/save")
save(body){
return this.json({success:true})
}
}
Code above will generate
POST /garage/save
{<payload body>}
You are free to assigned multiple http decorators into an action,
this behavior will make the action accessible from many routes.
export class CarController : Controller{
@http.post("/dashboard")
@http.post("/dashboard/property")
@http.post("/dashboard/property/car")
@http.post("/dashboard/property/car/list")
list(){
return this.json({success:true})
}
}
Internal Decorator
TypeScript's generated javascript doesn't leave information about
private method so KambojaJs will guess all of your method as public.
You can mark a method as @internal if you want KambojaJs exclude
the method from route generation.
export class CarController : Controller{
@internal()
private thisIsPrivate(){
return "sssttt.."
}
list(){
return this.json(this.thisIsPrivate())
}
}
Async/Await support
With TypeScript 2.1 support async/await on ES5, we can use it also
inside the controller
export class CarController : Controller{
@internal()
private slowLoadingAsync(): Promise<string>{ }
async list(){
let result = await this.slowLoadingAsync()
return this.json(result)
}
}
Error handling using try-catch
Another TypeScript 2.1 feature we also can do try-catch error
inside controller. The error will nicely passed through the
error handler.
export class CarController : Controller{
async list(){
try{
let result = await this.slowLoadingAsync()
return this.json(result)
}
catch(e){
throw new Error("Something bad happened")
}
}
}
Flexible Engine
KambojaJs not totally created from scratch instead it designed so it can sits on top
of another framework such as ExpressJs(implemented), Koa(in progress).
This is good so we can reuse any great existing library like BodyParser and some middleware
Smart Analysis
KambojaJs comes with smart analytic engine, it will identify common mistakes that hard to trace.
- Detect non exported controller
- Detect if there is controller not inherited from ApiController or Controller
- Detect if @internal decorator combined with @http.() decorator
- Detect if an Api Naming convention in an action fail caused by lack of parameters
- Detect un match parameter between route and action when using custom route
- Detect if Controller method accidentally overridden such as json, redirect, file, view
- Detect if there are duplicate route happened.