With ModularBr, the routes of your API can be defined in a clear and organized manner using the Route Handlers feature. With this feature, you can divide the implementations into separate classes that inherit from the TRouteHandler class, where each class is responsible for defining the corresponding routes and their handlers. Then, the list of classes that define the routes is registered in a single place - the RouteHandlers method of the AppModule module - making development and maintenance easier and more efficient.
By using Route Handlers, the code becomes more modular and easier to understand, allowing you to quickly find the implementations for each route. This means that you can have a more organized structure for handling the routes of your application, making maintenance and the addition of new features easier. With ModularBr, you have a powerful feature that helps make your API more efficient, organized, and easy to manage.
...
type
TAppModule = class(TModule)
public
function Routes: TRoutes; override;
function RouteHandlers: TRouteHandlers; override;
end;
implementation
...
function TAppModule.RouteHandlers: TRouteHandlers;
begin
Result := [TPDFRouteHandler];
end;
function TAppModule.Routes: TRoutes;
begin
Result := [RouteModule(Rota.Empresa, TEmpresaModule),
RouteModule(Rota.NFe, TNFeModule)];
end;
...
Initializing the Modular and the AppModule:
procedure TFormServer.StartRoutes;
begin
ReportMemoryLeaksOnShutdown := True;
// Registering to AppModule/Route Guardian
THorse.Use(HorseModular(TAppModule.Create));
// Putting the server online.
StartServer;
end;
procedure TFormServer.StartServer;
begin
THorse.Listen(9000);
end;