You are not logged in.
Pages: 1
How to create a restful class as using mormot
the TSQLHttpServer
but need to use restful, I use firebird and needed to have access to methods PUT / GET / DELETE
mormot are only example I use sqlite firebird
I have used directly as below but need RESTful.
unit UnitJson;
interface
uses
SynCommons, mORMot, mORMotHttpServer,mORMotReport,
System.SysUtils,Vcl.Forms, Winapi.Windows, System.Classes,Contnrs,XSBuiltIns,System.StrUtils;
type
TMyService = class(TSQLRestServerFullMemory)
published
procedure myapp(Ctxt: TSQLRestServerURIContext);
end;
TMyHTTPServer = class(TSQLHttpServer)
private
oModel: TSQLModel;
oSQLRestServerFullMemory: TMyService;
public
Model : TSQLModel;
function ServiceRegister(AImplementationClass: TInterfacedClass; const AInterfaces: PTypeInfo;const AContractExpected: RawUTF8): boolean;
constructor Create(const APorta: RawUTF8; AThreadPoolCount: Integer); reintroduce;
destructor Destroy; override;
end;
// Class Return
['{E6C6ADFD-5977-4759-B400-AA4140F1D683}']
function cadastrosCrud(acao,tabela,conteudo,ordem,ativo,start,limit,chave:String;StrJson:RawUTF8): RawJSON;
end;
TMyClassDirect = class(TInterfacedObject, IMyInterface)
public
function cadastrosCrud(acao,tabela,conteudo,ordem,ativo,start,limit,chave:String;strjson:RawUTF8): RawJSON;
end;
implementation
{ TMyService }
procedure TMyService.myapp(Ctxt: TSQLRestServerURIContext);
var
sFileName: TFileName;
begin
sFileName := Ctxt.ResourceFileName;
if sFileName = '' then
Ctxt.Redirect('myapp/index.html')
else
Ctxt.ReturnFile(ExtractFilePath(Application.ExeName) + sFileName, true);
end;
{ TMyHTTPServer }
constructor TMyHTTPServer.Create(const APorta: RawUTF8; AThreadPoolCount: Integer);
begin
oModel := TSQLModel.Create([], 'app');
oSQLRestServerFullMemory := TMyService.Create(oModel, '', false, false);
inherited Create(APorta, [oSQLRestServerFullMemory], '+', useHttpApiRegisteringURI, AThreadPoolCount);
end;
function TMyHTTPServer.ServiceRegister(AImplementationClass: TInterfacedClass; const AInterfaces: PTypeInfo; const AContractExpected: RawUTF8): boolean;
begin
oSQLRestServerFullMemory.ServiceRegister(AImplementationClass,[AInterfaces], sicSingle).ContractExpected := AContractExpected;
Result := true;
end;
destructor TMyHTTPServer.Destroy;
begin
FreeAndNil(oModel);
FreeAndNil(oSQLRestServerFullMemory);
inherited;
end;
{ TMyClassDirect }
function TMyClassDirect.cadastrosCrud(acao,tabela,conteudo,ordem,ativo,start,limit,chave:String;strjson:RawUTF8): RawJSON;
var
ExtjsVO : TExtjsVO;
ListaCadastros : TList;
CadastrosControl : TCadastrosController;
begin
ExtjsVO := TExtjsVO.Create;
ListaCadastros := TList.Create();
CadastrosControl := TCadastrosController.Create;
try
if CadastrosControl.Crud_Cadastros(acao,tabela,conteudo,ordem,ativo,start,limit,chave,ListaCadastros,strjson) then
begin
ExtjsVO.rows := ListaCadastros;
ExtjsVO.success := true;
ExtjsVO.total := CadastrosControl.Registros;
end
else
begin
ExtjsVO.success := False;
ExtjsVO.total := 0;
end;
except
on E: Exception do
begin
ExtjsVO.success := False;
ExtjsVO.rows := ListaCadastros;
ExtjsVO.total := 0;
end;
end;
Result := ObjectToJson(ExtjsVO,[]);
FreeAndNil(ExtjsVO);
FreeAndNil(ListaCadastros);
FreeAndNil(CadastrosControl);
Manager.CloseConnectionDef('Firebird_Pooled');
end;
end.
Offline
Not sure I understand you, but the mORMot is fundamentally based on the RESTful concept.
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
sorry if not expressed myself well.
how I capture methodos CREATE /GET / PUT / DELETE using TSQLHttpServer
I not found any examples of how to do this
I use Firebird 2.5 delphi 10 seatlle
thanks for the answer
Offline
Pages: 1