원클릭으로
horse-request-response
Guide to interacting with THorseRequest (body, query, params, headers) and THorseResponse (Send, Status, ContentType).
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Guide to interacting with THorseRequest (body, query, params, headers) and THorseResponse (Send, Status, ContentType).
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-request-response |
| description | Guide to interacting with THorseRequest (body, query, params, headers) and THorseResponse (Send, Status, ContentType). |
The THorseRequest object contains all details of the incoming HTTP request.
Req.Body. If the Jhonson middleware is active, you can read the parsed JSON directly:
var
LBody: TJSONObject;
begin
LBody := Req.Body<TJSONObject>;
end;
:name), use Req.Params.Items['name'] (or Req.Params['name']).?page=1&limit=10), use Req.Query.Items['page'] (or Req.Query['page']).Req.Headers.Items['Authorization'].Instead of accessing raw string dictionary values (e.g., Req.Params['id']) and converting them manually, always prefer using the .Field() method to obtain a THorseCoreParamField. This provides type-safe conversions and declarative parameter validation:
StrToInt or StrToBool:
var
LId: Integer;
LActive: Boolean;
LDate: TDateTime;
begin
LId := Req.Params.Field('id').AsInteger;
LActive := Req.Query.Field('active').AsBoolean;
LDate := Req.Query.Field('since').AsISO8601DateTime;
end;
var
LEmail: string;
begin
// Automatically raises EHorseException if 'email' query param is empty
LEmail := Req.Query.Field('email').Required.RequiredMessage('The "email" parameter is required.').AsString;
end;
AsInteger, AsInt64, AsBoolean, AsFloat, AsCurrency, AsDateTime, AsISO8601DateTime, AsStream (for multipart uploads), and AsString.Horse provides a provider-agnostic, typed API to read cookies from requests and write them back in responses (RFC 6265 compliant).
Reading Cookies: Read incoming cookies safely using the .Field() helper:
var
LSessionToken: string;
begin
LSessionToken := Req.Cookie.Field('session_token').AsString;
end;
Writing Cookies (Set-Cookie): Write response cookies using Res.Cookie and configure properties fluently:
uses Horse.Core.Cookie;
procedure SetCookieHandler(Req: THorseRequest; Res: THorseResponse; Next: TProc);
begin
// Creates, registers, and configures the cookie fluently (XE7 compatible)
Res.Cookie('session_id', 'xyz789')
.Path('/')
.HttpOnly(True)
.Secure(True)
.SameSite(TSameSite.ssLax);
Res.Send('Cookie has been set');
end;
The THorseResponse object is used to build and send the HTTP response back to the client.
// Sending simple text with Status 200 (OK)
Res.Send('Success');
// Setting Status 201 (Created) and sending an object (MUST set status BEFORE calling Send)
Res.Status(THTTPStatus.Created).Send<TJSONObject>(LJson);
THTTPStatus enum:
Res.Status(400); // Bad Request
Res.Status(THTTPStatus.NoContent);
Res.ContentType('text/html').Send('<h1>HTML Content</h1>');
To return error responses with custom HTTP statuses and error details, raise EHorseException. The framework captures this exception and formats it as a structured JSON error response:
uses Horse.Exception, Horse.Commons;
procedure GetProduct(Req: THorseRequest; Res: THorseResponse; Next: TProc);
var
LId: Integer;
LProduct: TProduct;
begin
LId := Req.Params.Field('id').AsInteger;
if LId <= 0 then
raise EHorseException.New
.Status(THTTPStatus.BadRequest)
.Error('Invalid product ID');
LProduct := FindProduct(LId);
if not Assigned(LProduct) then
raise EHorseException.New
.Status(THTTPStatus.NotFound)
.Error('Product not found')
.Code(4041)
.Detail('The requested product does not exist in our catalog.');
Res.Send(LProduct);
end;
When EHorseException is raised, it automatically serializes to a clean JSON response containing fields like error, code, and detail.