Core ConceptsComponents

Route Hooks

Route Hook is the new name for what was previously exported as config: RouterConfig. If you have existing code using export const config: RouterConfig, it still works but will log a deprecation warning. Migrating is a one-line change — see Migration from RouterConfig.

Route Hook is an Arkos component that lets you configure auto-generated routes without touching the route definitions themselves. It is a named export from your module's *.router.ts file where each key maps to a built-in operation, and each value is the same configuration object accepted by ArkosRouter.

src/modules/post/post.router.ts
import { ArkosRouter, RouteHook } from "arkos";

export const hook: RouteHook = {
  findMany: { authentication: false },
  createOne: {
    authentication: {
      resource: "post",
      action: "Create",
      rule: ["Admin"],
    },
  },
  deleteOne: { disabled: true },
};

const router = ArkosRouter();

export default router;

Configuration Object

Every key in a Route Hook accepts the same configuration object as ArkosRouter routes — authentication, validation, rate limiting, disabled, and more. See the full reference at ArkosRouter Configuration Object.

Prisma Model Route Hook

Configures the auto-generated RESTful endpoints for a Prisma model. The file lives at src/modules/<model>/<model>.router.ts.

KeyMethodEndpoint
findManyGET/api/[model]
findOneGET/api/[model]/:id
createOnePOST/api/[model]
updateOnePATCH/api/[model]/:id
deleteOneDELETE/api/[model]/:id
createManyPOST/api/[model]/many
updateManyPATCH/api/[model]/many
deleteManyDELETE/api/[model]/many
src/modules/post/post.router.ts
import { ArkosRouter, RouteHook } from "arkos";
import postPolicy from "@/src/modules/post/post.policy";
import UpdatePostSchema from "@/src/modules/post/post.schema";

export const hook: RouteHook<"auth"> = {
  findMany: { authentication: false },
  findOne: { authentication: true },
  createOne: { authentication: postPolicy.Create },
  updateOne: {
    authentication: postPolicy.Update,
    validation: { body: UpdatePostSchema },
  },
  deleteOne: { authentication: postPolicy.Delete },
  createMany: { disabled: true },
  updateMany: { disabled: true },
  deleteMany: { disabled: true },
};

const router = ArkosRouter();

export default router;
src/modules/post/post.router.ts
import { ArkosRouter, RouteHook } from "arkos";
import postAuthConfigs from "@/src/modules/post/post.auth";
import UpdatePostSchema from "@/src/modules/post/post.schema";

export const hook: RouteHook = {
  findMany: { authentication: false },
  findOne: { authentication: true },
  createOne: {
    authentication: {
      resource: "post",
      action: "Create",
      rule: postAuthConfigs.accessControl.Create,
    },
  },
  updateOne: {
    authentication: {
      resource: "post",
      action: "Update",
      rule: postAuthConfigs.accessControl.Update,
    },
    validation: { body: UpdatePostSchema },
  },
  deleteOne: {
    authentication: {
      resource: "post",
      action: "Delete",
      rule: postAuthConfigs.accessControl.Delete,
    },
  },
  createMany: { disabled: true },
  updateMany: { disabled: true },
  deleteMany: { disabled: true },
};

const router = ArkosRouter();

export default router;

See Model Routes for the full breakdown of generated endpoints and query capabilities.

Authentication Route Hook

Configures the built-in authentication endpoints. The file lives at src/modules/auth/auth.router.ts.

KeyMethodEndpoint
loginPOST/api/auth/login
signupPOST/api/auth/signup
logoutDELETE/api/auth/logout
updatePasswordPOST/api/auth/update-password
getMeGET/api/users/me
updateMePATCH/api/users/me
deleteMeDELETE/api/users/me
src/modules/auth/auth.router.ts
import { ArkosRouter, RouteHook } from "arkos";
import UpdateMeSchema from "@/src/modules/auth/schemas/update-me.schema";

export const hook: RouteHook<"auth"> = {
  login: { rateLimit: { windowMs: 15 * 60_000, max: 10 } },
  signup: { disabled: true },
  getMe: { rateLimit: { windowMs: 15 * 60_000, max: 30 } },
  deleteMe: { disabled: true },
  updateMe: { validation: { body: UpdateMeSchema } },
  updatePassword: { rateLimit: { windowMs: 15 * 60_000, max: 10 } },
};

const router = ArkosRouter();

export default router;

See Authentication Routes for the full breakdown of auth endpoints and request/response shapes.

File Upload Route Hook

Configures the built-in standalone file upload endpoints. The file lives at src/modules/file-upload/file-upload.router.ts.

KeyMethodEndpoint
findFileGET/api/uploads/:fileType/:fileName
uploadFilePOST/api/uploads/:fileType
updateFilePATCH/api/uploads/:fileType/:fileName
deleteFileDELETE/api/uploads/:fileType/:fileName
src/modules/file-upload/file-upload.router.ts
import { ArkosRouter, RouteHook } from "arkos";

export const hook: RouteHook<"file-upload"> = {
  findFile: { authentication: false },
  uploadFile: { authentication: true },
  updateFile: { authentication: true },
  deleteFile: { disabled: true },
};

const router = ArkosRouter();

export default router;

See File Upload Routes for the full breakdown of file upload endpoints and request/response shapes.

Migration from RouterConfig

Since v1.6, RouteHook replaces RouterConfig as the recommended export name. The old name still works but will log a deprecation warning:

[Warn] 10:35:09 `export const config: RouterConfig` in post.router.ts is deprecated.
Use `export const hook: RouteHook` instead.

Migrating is a one-line change per file:

// before
export const config: RouterConfig = { ... };

// after
export const hook: RouteHook = { ... };