delphimvcframework/samples/middleware_analytics/MainControllerU.pas

108 lines
2.4 KiB
ObjectPascal
Raw Normal View History

2019-01-08 12:48:27 +01:00
unit MainControllerU;
interface
uses
MVCFramework, MVCFramework.Commons;
type
[MVCPath('/api')]
TMainController = class(TMVCController)
public
2020-09-02 19:43:34 +02:00
[MVCPath('/')]
2019-01-08 12:48:27 +01:00
[MVCHTTPMethod([httpGET])]
procedure Index;
[MVCPath('/reversedstrings/($Value)')]
[MVCHTTPMethod([httpGET])]
procedure GetReversedString(const Value: String);
protected
procedure OnBeforeAction(Context: TWebContext; const AActionName: string; var Handled: Boolean); override;
procedure OnAfterAction(Context: TWebContext; const AActionName: string); override;
public
//Sample CRUD Actions for a "Customer" entity
[MVCPath('/customers')]
[MVCHTTPMethod([httpGET])]
procedure GetCustomers;
[MVCPath('/customers/($id)')]
[MVCHTTPMethod([httpGET])]
procedure GetCustomer(id: Integer);
[MVCPath('/customers')]
[MVCHTTPMethod([httpPOST])]
procedure CreateCustomer;
[MVCPath('/customers/($id)')]
[MVCHTTPMethod([httpPUT])]
procedure UpdateCustomer(id: Integer);
[MVCPath('/customers/($id)')]
[MVCHTTPMethod([httpDELETE])]
procedure DeleteCustomer(id: Integer);
end;
implementation
uses
System.SysUtils, MVCFramework.Logger, System.StrUtils;
procedure TMainController.Index;
begin
//use Context property to access to the HTTP request and response
Render('Hello DelphiMVCFramework World');
end;
procedure TMainController.GetReversedString(const Value: String);
begin
Render(System.StrUtils.ReverseString(Value.Trim));
end;
procedure TMainController.OnAfterAction(Context: TWebContext; const AActionName: string);
begin
{ Executed after each action }
inherited;
end;
procedure TMainController.OnBeforeAction(Context: TWebContext; const AActionName: string; var Handled: Boolean);
begin
{ Executed before each action
if handled is true (or an exception is raised) the actual
action will not be called }
inherited;
end;
//Sample CRUD Actions for a "Customer" entity
procedure TMainController.GetCustomers;
begin
//todo: render a list of customers
end;
procedure TMainController.GetCustomer(id: Integer);
begin
//todo: render the customer by id
end;
procedure TMainController.CreateCustomer;
begin
//todo: create a new customer
end;
procedure TMainController.UpdateCustomer(id: Integer);
begin
//todo: update customer by id
end;
procedure TMainController.DeleteCustomer(id: Integer);
begin
//todo: delete customer by id
end;
end.