04-19-2023, 05:23 AM
(This post was last modified: 04-19-2023, 05:25 AM by Alexandre Machado.)
Hi Matija,
I asked you some questions via email, but this is a job for content handlers.
The content handler can be registered to any URL path and respond with any type of content.
Basically you would create something like this:
and your content handler would look like this:
This is a very generic content handler implementation where the response can be anything (a plain text file, a JSON or XML content, a full HTML page, an HTML fragment, JavaScript, whatever you want).
The important part here is to determine what the caller expects to receive and how it intends to use the content provided by the content handler...
I asked you some questions via email, but this is a job for content handlers.
The content handler can be registered to any URL path and respond with any type of content.
Basically you would create something like this:
Code:
myHandler := TMyContentHandler.Create;
THandlers.Add('/articles/', '/article-1', myHandler);
and your content handler would look like this:
Code:
unit uMyContentHandler;
interface
uses
Classes, IW.Content.Base, IWApplication, IW.HTTP.Request, IW.HTTP.Reply;
type
TMyContentHandler = class(TContentBase)
protected
function Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string;
aSession: TIWApplication; aParams: TStrings): Boolean; override;
public
constructor Create; override;
end;
implementation
constructor TMyContentHandler.Create;
begin
inherited;
mFileMustExist := False;
end;
function TMyContentHandler.Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string;
aSession: TIWApplication; aParams: TStrings): Boolean;
begin
Result := True;
if Assigned(aReply) then begin
aReply.WriteString('this is whatever you want to return to the caller');
end;
end;
end.
This is a very generic content handler implementation where the response can be anything (a plain text file, a JSON or XML content, a full HTML page, an HTML fragment, JavaScript, whatever you want).
The important part here is to determine what the caller expects to receive and how it intends to use the content provided by the content handler...