2013-10-29 16:51:16 +01:00
|
|
|
unit App1MainControllerU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses MVCFramework,
|
|
|
|
MVCFramework.Logger,
|
|
|
|
Web.HTTPApp;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
[MVCPath('/')]
|
|
|
|
TApp1MainController = class(TMVCController)
|
|
|
|
public
|
|
|
|
[MVCPath('/')]
|
|
|
|
[MVCHTTPMethod([httpGET])]
|
2016-06-22 17:49:16 +02:00
|
|
|
procedure Index;
|
2013-10-29 16:51:16 +01:00
|
|
|
|
|
|
|
[MVCPath('/hello')]
|
|
|
|
[MVCHTTPMethod([httpGET])]
|
2016-06-22 17:49:16 +02:00
|
|
|
procedure HelloWorld;
|
2013-10-29 16:51:16 +01:00
|
|
|
|
|
|
|
[MVCPath('/hello')]
|
|
|
|
[MVCHTTPMethod([httpPOST])]
|
2016-06-22 17:49:16 +02:00
|
|
|
procedure HelloWorldPost;
|
2013-10-29 16:51:16 +01:00
|
|
|
|
|
|
|
[MVCPath('/div/($par1)/($par2)')]
|
|
|
|
[MVCHTTPMethod([httpGET])]
|
2016-06-22 17:49:16 +02:00
|
|
|
procedure RaiseException(par1, par2: String);
|
2013-10-29 16:51:16 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2014-11-19 12:27:37 +01:00
|
|
|
{$IF CompilerVersion >= 27} System.JSON,
|
2014-05-11 19:29:20 +02:00
|
|
|
{$ELSE} Data.DBXJSON,
|
|
|
|
{$ENDIF}
|
2013-10-29 16:51:16 +01:00
|
|
|
System.SysUtils;
|
|
|
|
|
|
|
|
{ TApp1MainController }
|
|
|
|
|
2016-06-22 17:49:16 +02:00
|
|
|
procedure TApp1MainController.HelloWorld;
|
2013-10-29 16:51:16 +01:00
|
|
|
begin
|
|
|
|
Render('Hello World called with GET');
|
2016-06-22 17:49:16 +02:00
|
|
|
if Context.Request.ThereIsRequestBody then
|
|
|
|
Log('Body:' + Context.Request.Body);
|
2013-10-29 16:51:16 +01:00
|
|
|
end;
|
|
|
|
|
2016-06-22 17:49:16 +02:00
|
|
|
procedure TApp1MainController.HelloWorldPost;
|
2013-10-29 16:51:16 +01:00
|
|
|
var
|
2014-05-11 19:29:20 +02:00
|
|
|
JSON: TJSONObject;
|
2013-10-29 16:51:16 +01:00
|
|
|
begin
|
2016-06-22 17:49:16 +02:00
|
|
|
JSON := Context.Request.BodyAsJSONObject;
|
2014-05-11 19:29:20 +02:00
|
|
|
JSON.AddPair('modified', 'from server');
|
|
|
|
Render(JSON, false);
|
2013-10-29 16:51:16 +01:00
|
|
|
Log('Hello world called with POST');
|
|
|
|
end;
|
|
|
|
|
2016-06-22 17:49:16 +02:00
|
|
|
procedure TApp1MainController.Index;
|
2013-10-29 16:51:16 +01:00
|
|
|
begin
|
2014-05-11 19:29:20 +02:00
|
|
|
Redirect('index.html');
|
2013-10-29 16:51:16 +01:00
|
|
|
end;
|
|
|
|
|
2016-06-22 17:49:16 +02:00
|
|
|
procedure TApp1MainController.RaiseException(par1, par2: String);
|
2013-10-29 16:51:16 +01:00
|
|
|
var
|
|
|
|
R: Extended;
|
|
|
|
begin
|
2016-06-22 17:49:16 +02:00
|
|
|
Log('Parameter1=' + QuotedStr(par1));
|
|
|
|
Log('Parameter2=' + QuotedStr(par2));
|
|
|
|
R := StrToInt(par1) / StrToInt(par2);
|
2013-10-29 16:51:16 +01:00
|
|
|
Render(TJSONObject.Create(TJSONPair.Create('result', TJSONNumber.Create(R))));
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|