@axonlabs/core
    Preparing search index...

    Class AxonRouter

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    prefix: undefined | string

    Methods

    • Endpoint with method DELETE

      The DELETE HTTP request method sends data to the server for deleting a data.

      Type Parameters

      • Path extends string
      • C extends BaseController
      • M extends string | number | symbol

      Parameters

      • path: Path

        route path

      • controller: FuncController<RouteParams<Path>> | ClassController<C, M>

        route request controller

      • Optionalvalidation: ValidationObj[]

        an array contains your validation objects

      Returns AxonRouteHandler<RouteParams<Path>>

      router.delete("/user/{param}(regex)", (req: Request<{ param: string }>, res: Response) => {
      res.send("Hello World");
      });

      router.delete("/logout", authController, [
      {
      schema: logoutSchema,
      target: "params",
      options: {
      abortEarly: false
      }
      }
      ])
    • Endpoint with method GET

      The purpose of the GET method is to simply retrieve data from the server. The GET method is used to request any of the following resources:

      • A webpage or HTML file.
      • An image or video.
      • A JSON document.
      • A CSS file or JavaScript file.
      • An XML file.

      Type Parameters

      • Path extends string
      • C extends BaseController
      • M extends string | number | symbol

      Parameters

      Returns AxonRouteHandler<RouteParams<Path>>

      router.get("/user/{param}(regex)", (req: Request<{ param: string }>, res: Response) => {
      res.send("Hello World");
      });

      router.get("/user", userController, [
      {
      schema: limitSchema,
      target: "query",
      options: {
      abortEarly: false
      }
      }
      ])
    • Endpoint with method OPTIONS

      The HTTP OPTIONS method returns a listing of which HTTP methods are supported and allowed.

      Type Parameters

      • Path extends string
      • C extends BaseController
      • M extends string | number | symbol

      Parameters

      Returns AxonRouteHandler<RouteParams<Path>>

      router.options("/user/{param}(regex)", (req: Request<{ param: string }>, res: Response) => {
      res.send("Hello World");
      });
    • Endpoint with method PATCH

      The PATCH HTTP request method sends data to the server for editing part of a data.

      Type Parameters

      • Path extends string
      • C extends BaseController
      • M extends string | number | symbol

      Parameters

      Returns AxonRouteHandler<RouteParams<Path>>

      router.patch("/user/{param}(regex)", (req: Request<{ param: string }>, res: Response) => {
      res.send("Hello World");
      });

      router.patch("/edit", userController, [
      {
      schema: editSchema,
      target: "body",
      options: {
      abortEarly: false
      }
      },
      {
      schema: userSchema,
      target: "params"
      }
      ])

    post

    • post<
          Path extends string,
          C extends BaseController,
          M extends string | number | symbol,
      >(
          path: Path,
          controller: FuncController<RouteParams<Path>> | ClassController<C, M>,
          validation?: ValidationObj[],
      ): AxonRouteHandler<RouteParams<Path>>

      Endpoint with method POST

      The POST HTTP request method sends data to the server for processing.

      The data sent to the server is typically in the following form:

      • Input fields from online forms.
      • XML or JSON data.
      • Text data from query parameters.

      Type Parameters

      • Path extends string
      • C extends BaseController
      • M extends string | number | symbol

      Parameters

      Returns AxonRouteHandler<RouteParams<Path>>

      router.post("/user/{param}(regex)", (req: Request<{ param: string }>, res: Response) => {
      res.send("Hello World");
      });

      router.post("/login", authController, [
      {
      schema: loginSchema,
      target: "body",
      options: {
      abortEarly: false
      }
      }
      ])
    • Endpoint with method PUT

      The PUT HTTP request method sends data to the server for replacing and changing full state.

      Type Parameters

      • Path extends string
      • C extends BaseController
      • M extends string | number | symbol

      Parameters

      Returns AxonRouteHandler<RouteParams<Path>>

      router.put("/user/{param}(regex)", (req: Request<{ param: string }>, res: Response) => {
      res.send("Hello World");
      });

      router.put("/edit", userController, [
      {
      schema: editSchema,
      target: "body",
      options: {
      abortEarly: false
      }
      }
      ])