capture JSON object sent via POST in Mormot request payload

0

I am sending my object JSON via POST using ExtJS 6.01 . my application server was done in morMot in Delphi Seattle . Sending in GET mode usually takes the parameters that come with url .

But sending via POST my object is placed in Request PayLoad how to get this data sent via POST , using morMot framework ?

unit UnitJson;

interface
uses
  SynCommons, mORMot, mORMotHttpServer,mORMotReport, mORMotHttpClient,SynCrtSock,
  System.SysUtils,Vcl.Forms, Winapi.Windows, System.Classes,DB,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;

 TServiceCustomAnswer = record
    Header: RawUTF8;
    Content: RawUTF8;
  end;

type
   TExtjsVO = class
  private
    fsuccess : boolean;
    frows     : TList;
    ftotal    : integer;
  published
    property success    : boolean            read Fsuccess write Fsuccess;
    property rows       : TList              read Frows    write Frows;
    property total      : integer            read Ftotal   write Ftotal;
  end;


// Class Return
  IMyInterface = interface(IInvokable)
  ['{E6C6ADFD-5977-4759-B400-AA4140F1D683}']
    function PostItem(params:RawUTF8):RawJSON;
  end;

  TMyClassDirect = class(TInterfacedObject, IMyInterface)

  public
    function PostItem(params:RawUTF8):RawJSON;
  end;

implementation

uses UnitServer;

{ 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.PostItem(params:RawUTF8): RawJSON;
begin
  // nao consigo pegar os dados via POST aqui..
  Result   := params;

end;

end.
    
asked by anonymous 18.02.2016 / 21:00

1 answer

-1

I only used mormot as a restfull and custom method I do not know if it helps you but I get the json no call.inbody

procedure doSomething(Ctxt: TSQLRestServerURIContext);
var
  MyJson: String;
begin
  MyJson := Ctxt.Call.InBody;
  ...
end;

I hope I have helped you with something

    
09.02.2017 / 14:42