Convention Over Configuration

KambojaJS route generation system generate url using pattern below:


Example you define controller like below

import { Controller } from "kamboja"

export namespace Api.v01
  export class UserController extends Controller {
    list(query:string, offset:number, limit:number){ }

Above code by default will generate a GET url below


Refer to controller reference for more information

For more advanced use, KambojaJS provide a convention for creating Restful API by using ApiController

Example controller below will create Restful API url for you

import { ApiController } from "kamboja"

namespace Api.V1 {
    export class ItemsController extends ApiController {
        //GET /api/v1/items/:id
        get(id:string) { }
        //GET /api/v1/items?offset=1&limit=<optional>
        list(offset:number, limit=50){ }
        //POST /api/v1/items
        add(data){ }
        //DELETE /api/v1/items/:id
        delete(id:string){ }
        //PUT /api/v1/items/:id
        replace(id:string, data){ }
        //PATCH /api/v1/items/:id
        modify(id:string, data){}

Above code will generate some urls:

GET     /api/v1/items/:id
GET     /api/v1/items?offset=1&limit=<optional>
POST    /api/v1/items
DELETE  /api/v1/items/:id
PUT     /api/v1/items/:id
PATCH   /api/v1/items/:id

Refer to ApiController for more information