Skip to main content

Controller

Controllers are responsible for handling incoming requests and returning responses to the client.

Table of Contents

Register

all controller registration use as below:

Controller Register

controllerRegister(schema:ControllerSchema,opt:ControllerRegisterOptions);

schema define what this route is, where it must initiate and which middlewares use for it

type ControllerSchema = {
  url?: string;
  method: 'get' | 'post' | 'put' | 'patch' | 'delete';
  access?: ControllerAccess | ControllerAccess[];
  service: MiddleWare | MiddleWare[];
  validate?: ValidateArgs | ValidateArgs[] | null;
};

options define who register this route and how registration must work

type ControllerRegisterOptions = {
  base_url?: string | string[];
  strategy?: 'replace' | 'insertAfter' | 'insertFirst';
} & RegisterOptions

Controller Register Batch

use array of ControllerSchema for register:

function controllersBatchRegister(
  schemas: ControllerSchema[],
  opt: ControllerRegisterOptions
);