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;
|
|
|
|
|
2022-08-13 00:21:00 +02:00
|
|
|
[MVCPath('/error')]
|
|
|
|
[MVCHTTPMethod([httpGET])]
|
|
|
|
procedure DoError;
|
|
|
|
|
2019-01-08 12:48:27 +01:00
|
|
|
[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
|
2022-08-13 00:21:00 +02:00
|
|
|
System.SysUtils, MVCFramework.Logger, System.StrUtils, MVCFramework.Serializer.Commons;
|
2019-01-08 12:48:27 +01:00
|
|
|
|
|
|
|
procedure TMainController.Index;
|
|
|
|
begin
|
2022-08-13 00:21:00 +02:00
|
|
|
//use Context property to access to the HTTP request and response
|
|
|
|
Render(StrDict(['hello'],['world']));
|
2019-01-08 12:48:27 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-13 00:21:00 +02:00
|
|
|
procedure TMainController.DoError;
|
|
|
|
begin
|
|
|
|
raise EMVCException.Create('This is an error');
|
|
|
|
end;
|
|
|
|
|
2019-01-08 12:48:27 +01:00
|
|
|
end.
|