• A class decorator that encapsulates API endpoints

    Type Parameters

    • T extends Class<object>

      Type of the annotated class

    Parameters

    • controllerPath: string

      Base path of the API endpoints

    • container: {} = defaultContainer

      Object that stores injectables

      Returns ClassDecorator<T>

      Remarks

      @Controller represents a specific API entrypoint. It expects the API path as a parameter

      The HTTP method annotations @Get, @Put, @Post, @Patch, @Delete take the API endpoint path as an optional paramater

      Example

      import {
      Cache,
      Controller,
      Get,
      Head,
      Options,
      Purge,
      Put,
      Post,
      Patch,
      Delete,
      } from "@fork-git-it/annotatedjs";

      @Controller("/items")
      export class ExampleController {
      @Options()
      async allowedMethods(req: Request): Promise<Response> {}

      @Get()
      async getItems(req: Request): Promise<Response> {}

      @Cache("cacheName")
      @Head("/:id")
      async headItem(req: Request): Promise<Response> {}

      @Cache("cacheName")
      @Get("/:id")
      async getItem(req: Request): Promise<Response> {}

      @Purge("cacheName")
      @Put("/:id")
      async putItem(req: Request): Promise<Response> {}

      @Post("/:id")
      async postItem(req: Request): Promise<Response> {}

      @Purge("cacheName")
      @Patch("/:id")
      async patchItem(req: Request): Promise<Response> {}

      @Delete()
      async deleteItems(req: Request): Promise<Response> {}

      @Purge("cacheName")
      @Delete("/:id")
      async deleteItem(req: Request): Promise<Response> {}
      }

    Generated using TypeDoc