Built-in Routers
Arkos provides several built-in routers that handle common API functionalities out of the box. This document outlines each router, its purpose, and how to configure it.
The following code snippets represent Arkos's behind-the-scenes implementation of each built-in router.
Welcome Endpoint Router
A simple welcome endpoint that responds with a configurable message.
app.get("/api", (req, res) => {
res.status(200).json({ message: arkosConfig.welcomeMessage });
});
Configuration Options:
- Customize the welcome message via
arkosConfig.welcomeMessage
Customization:
- Can be disabled or replaced with your own implementation
- See Modifying Built-in Routers Guide
File Uploader Router
Handles file uploads, serving static files, and file deletion operations.
Key Endpoints:
GET /api/uploads/:fileType/:fileName
- Serves uploaded filesPOST /api/uploads/:fileType
- Uploads a fileDELETE /api/uploads/:fileType/:fileName
- Deletes a file
Configuration Options:
- Set base route via
fileUpload.baseRoute
(default:/api/uploads
) - Configure upload directory via
fileUpload.baseUploadDir
(default:uploads
) - Customize static file serving with
fileUpload.expressStaticOptions
Customization:
- Can be disabled or replaced with your own implementation
- See Modifying Built-in Routers Guide
Learn More:
Authentication Router
Provides authentication endpoints for user management.
Key Endpoints:
GET|PATCH|DELETE /api/users/me
- Get, update, or delete current userPOST /api/auth/login
- User loginDELETE /api/auth/logout
- User logoutPOST /api/auth/signup
- User registrationPOST /api/auth/update-password
- Update user password
Configuration Options:
- Rate limiting via
arkosConfig.authentication.requestRateLimitOptions
- Only enabled when
arkosConfig.authentication
is provided
Customization:
- Can be disabled or replaced with your own implementation
- See Modifying Built-in Routers Guide
Learn More:
Prisma Models Router
Automatically generates RESTful API endpoints for all your Prisma models.
Generated Endpoints for Each Model:
GET /api/[pluralized-model-name]
- List all resourcesPOST /api/[pluralized-model-name]
- Create a resourceGET /api/[pluralized-model-name]/:id
- Get a specific resourcePATCH /api/[pluralized-model-name]/:id
- Update a specific resourceDELETE /api/[pluralized-model-name]/:id
- Delete a specific resourcePOST /api/[pluralized-model-name]/many
- Create multiple resourcesPATCH /api/[pluralized-model-name]/many
- Update multiple resourcesDELETE /api/[pluralized-model-name]/many
- Delete multiple resources
Configuration Options:
- Customize with model-specific middlewares and auth configs
- Configure Prisma query options for each operation
Customization:
- Can be disabled or replaced with your own implementation
- See Customizing Prisma Models Routers Guide
Learn More:
Available Resources & Routes Router
Provides endpoints to discover available API resources and routes.
Key Endpoints:
GET /api/available-routes
- Lists all available API routesGET /api/available-resources
- Lists all available API resources
Learn More:
Modifying Built-in Routers
To disable or replace built-in routers:
// src/app.ts
import arkos from "arkos";
arkos.init({
routers: {
// Disable specific routers
disable: ["welcome-endpoint", "file-uploader"],
// Replace routers with custom implementations
replace: {
authRouter: async (config) => {
// Your custom auth router implementation
return customAuthRouter;
},
},
},
// other configs
});
See Customizing Prisma Models Routers to learn how to customize without disabling or replacing the prisma models routers.
Adding Custom Routers
To add your own routers to the stack:
// src/app.ts
import arkos from "arkos";
import myCustomRouter from "./routers/my-custom.router";
arkos.init({
routers: {
additional: [myCustomRouter],
},
// other configs
});