一键导入
horse-routing
Guidelines for setting up endpoints, defining path parameters, route wildcards, and structuring HTTP controllers.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guidelines for setting up endpoints, defining path parameters, route wildcards, and structuring HTTP controllers.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Guidelines and workflows for developing and maintaining regular expressions and optional parameter routing features in the Horse framework.
Guidelines for registering, executing, and optimizing native high-precision telemetry hooks (AddOnTelemetry) in the Horse Web Framework.
Guidelines for instantiating and configuring independent Horse server instances (THorseInstance) running concurrently on different ports.
Guide for setting up thread-safe database connection pooling (FireDAC / UniDAC) in multithreaded Horse applications.
Guide for managing request-scoped contextual services and IoC (dependency injection) in Delphi and Lazarus.
Guide to using standard Horse middlewares (CORS, Jhonson, compression, basic-auth, logger) and pipeline registration order.
| name | horse-routing |
| description | Guidelines for setting up endpoints, defining path parameters, route wildcards, and structuring HTTP controllers. |
Horse supports registering endpoints for all standard HTTP verbs using static or instance methods:
THorse.Get('/products', GetProductsHandler);
THorse.Post('/products', CreateProductHandler);
THorse.Put('/products', UpdateProductHandler);
THorse.Delete('/products', DeleteProductHandler);
THorse.Patch('/products', PatchProductHandler);
Path parameters are defined using the colon syntax (:param):
THorse.Get('/users/:id', GetUserHandler);THorse.Get('/users/{id}', GetUserHandler);Inside the handler, you access the parameter via Req.Params.Items['id'] (or Req.Params['id']).
Use the wildcard asterisk (*) to match any subpath:
// Matches /public/css/site.css, /public/images/logo.png, etc.
THorse.Get('/public/*', ServeStaticFilesHandler);
You can group related routes under a common path prefix using THorse.Group. This is highly useful for API versioning (e.g., /v1) and isolating group-level middlewares:
Prefixing Routes:
THorse.Group.Prefix('/v1')
.Get('/products', GetProductsHandler)
.Get('/customers', GetCustomersHandler);
Group-level Middlewares (Restricted Middlewares):
Instead of registering a middleware globally via THorse.Use, you can register it specifically for a group using .Use(). The middleware will only run for endpoints defined inside that group:
THorse.Group.Prefix('/admin')
.Use(AuthMiddleware) // Only runs for routes under /admin
.Get('/dashboard', GetDashboardHandler)
.Get('/settings', GetSettingsHandler);
You can pass an array of route-specific middlewares (array of THorseCallback) to apply checks only to a single endpoint. These run after global and group-level middlewares:
Static routing:
THorse.Get('/admin/dashboard', [AuthMiddleware, LoggerMiddleware], GetDashboardHandler);
Fluent routing:
THorse.Route('/reports')
.Get([AuthMiddleware, LoggerMiddleware], GetReportsHandler)
.Post([AuthMiddleware], CreateReportHandler);
To keep routes organized, group them logically within static class methods or dedicated units:
type
TUserController = class
public
class procedure RegisterRoutes;
class procedure ListUsers(Req: THorseRequest; Res: THorseResponse; Next: TProc);
end;
class procedure TUserController.RegisterRoutes;
begin
THorse.Get('/users', ListUsers);
end;