Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

Nest4D

Nest4D: Um framework inspirado no NestJS para Delphi com o poderoso Horse!

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

Nest4D

Nest4D

Um framework inspirado no NestJS para Delphi com o poderoso Horse!

Este repositório está aberto para contribuições!

Sinta-se encorajado a abrir issues, enviar pull requests ou compartilhar ideias para melhorar este projeto. Toda ajuda é bem-vinda!

Ponto de entrada

pascal
  try
    TNest4DApplication.NewApplication(TAppModule,
      procedure(app: TNest4DApplication)
      begin
        app.Start();
      end);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;

Modulo

pascal
uses
  Nest4D.Interfaces;

type
  TAppModule = Class(TInterfacedObject, IN4DModule)
  public
    function Imports: TArray<TClass>;
    function Services: TArray<TClass>;
    function Controllers: TArray<TClass>;
  End;

implementation

uses
  app.controller,
  app.service;

{ TAppModule }

function TAppModule.Controllers: TArray<TClass>;
begin
  Result := [TAppController];
end;

function TAppModule.Imports: TArray<TClass>;
begin
  Result := [];
end;

function TAppModule.Services: TArray<TClass>;
begin
  Result := [TAppService];
end;

Controller

pascal
uses
  System.Json,
  Nest4D.Attributes,
  app.service;

type
  [N4DController('/api')]
  TAppController = Class
  private
    FAppService: TAppService;
  public
    [N4DRoute(Get, '')]
    function getApi: TJsonObject;

    constructor Create(AAppService: TAppService);
  End;
                       
implementation

{ TAppController }

constructor TAppController.Create(AAppService: TAppService);
begin
  FAppService := AAppService;
end;

function TAppController.getApi: TJsonObject;
begin
  Result := TJSONObject.Create.AddPair('message', 'Hello, World!');
end;