2013-10-29 16:51:16 +01:00
|
|
|
unit App1MainControllerU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
2017-01-05 12:44:34 +01:00
|
|
|
{$I dmvcframework.inc}
|
|
|
|
|
2020-03-21 23:58:09 +01:00
|
|
|
|
2013-10-29 16:51:16 +01:00
|
|
|
uses MVCFramework,
|
|
|
|
MVCFramework.Logger,
|
2017-03-30 17:00:04 +02:00
|
|
|
MVCFramework.Commons,
|
2013-10-29 16:51:16 +01:00
|
|
|
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])]
|
2020-03-21 23:58:09 +01:00
|
|
|
[MVCProduces(TMVCMediaType.TEXT_HTML)]
|
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])]
|
2020-03-21 23:58:09 +01:00
|
|
|
procedure RaiseException(const par1, par2: integer);
|
2013-10-29 16:51:16 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2017-05-25 16:57:49 +02:00
|
|
|
System.SysUtils,
|
2020-03-21 23:58:09 +01:00
|
|
|
MVCFramework.Serializer.JSONDataObjects,
|
|
|
|
JSONDataObjects;
|
2013-10-29 16:51:16 +01:00
|
|
|
|
|
|
|
{ TApp1MainController }
|
|
|
|
|
2016-06-22 17:49:16 +02:00
|
|
|
procedure TApp1MainController.HelloWorld;
|
2013-10-29 16:51:16 +01:00
|
|
|
begin
|
2020-03-21 23:58:09 +01:00
|
|
|
Render('Hello World! It''s ' + TimeToStr(Time) + ' in the DMVCFramework Land!');
|
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
|
2020-03-21 23:58:09 +01:00
|
|
|
lJSON: TJSONObject;
|
2013-10-29 16:51:16 +01:00
|
|
|
begin
|
2020-03-21 23:58:09 +01:00
|
|
|
lJSON := StrToJSONObject(Context.Request.Body);
|
2017-03-30 17:00:04 +02:00
|
|
|
try
|
2020-03-21 23:58:09 +01:00
|
|
|
Log.Info('Hello world called with POST (request is: ' + lJSON.ToJSON(True) + ')', 'basicdemo');
|
|
|
|
lJSON.S['modified'] := 'from server';
|
|
|
|
Render(lJSON, false);
|
2017-03-30 17:00:04 +02:00
|
|
|
finally
|
2020-03-21 23:58:09 +01:00
|
|
|
lJSON.Free;
|
2017-03-30 17:00:04 +02:00
|
|
|
end;
|
2013-10-29 16:51:16 +01:00
|
|
|
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;
|
|
|
|
|
2020-03-21 23:58:09 +01:00
|
|
|
procedure TApp1MainController.RaiseException(const par1, par2: integer);
|
2013-10-29 16:51:16 +01:00
|
|
|
var
|
2020-03-21 23:58:09 +01:00
|
|
|
lFS: TFormatSettings;
|
2013-10-29 16:51:16 +01:00
|
|
|
begin
|
2020-03-21 23:58:09 +01:00
|
|
|
lFS.DecimalSeparator := '.';
|
|
|
|
Log.Info('Parameter1=%d', [par1], 'basicdemo');
|
|
|
|
Log.Info('Parameter2=%d', [par2], 'basicdemo');
|
|
|
|
Render(
|
|
|
|
StrDict.Add('result', FloatToStr(par1 / par2, lFS))
|
|
|
|
);
|
2013-10-29 16:51:16 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|