#1 Re: mORMot 1 » one-to-many and REST POST Method » 2012-11-15 17:42:10

For method-based services do you mean ModelRoot/TableName/ID/MethodName? This is what I'm trying to do. right now...

My goal is a http only REST API server exposing resources to remote clients (iOS,Android,html/js,external web services) with all business logic residing on the server. Do you think that is feasible?

It would be possible to develop a resource only mORMot server (/ModelRoot/TableName/ID/AnotherTableName/ID...)?

Thanks,
Mauro

#2 Re: mORMot 1 » one-to-many and REST POST Method » 2012-11-14 18:56:00

:) I beg your pardon for my english!

I try to simplify my request:

TSQLTableName1 = Class(TSQLRecord)
TSQLTableName2 = Class(TSQLRecord)
...
TMethodName1   = Class(TInterfacedObject,...)
TMethodName2   = Class(TInterfacedObject,...)
...

aServer.ServiceRegister(TMethodName2,...)

POST /ModelRoot/TableName1/ID/MethodName2 <- {"create a new TableName2 record with TableName1 ID reference"}

It's correct!? I'm trying to "simulate" a resource only REST URL.

Thanks,
Mauro

#3 Re: mORMot 1 » one-to-many and REST POST Method » 2012-11-14 15:57:18

if resource only REST methods are not allowed (/ModelRoot/TableName1/ID/TableName2/ID) I guessing that mORMot way is tables/methods mixed style (/ModelRoot/TableName1/ID/MethodTableName2), is it RESTful anyway?

Do you think mORMot could support resource only REST methods in a future version or do you belive it's useless?

Thanks,
Mauro

#4 Re: mORMot 1 » one-to-many and REST POST Method » 2012-11-13 11:59:02

> No, it is not possible as this.

OK!

>You'll have to search for all the Childs with Parents=ParentID in the share WHERE clause.
>There is no direct REST routing for such requests.

It's possible to have just a little example about this (MainDemo doesn't explain exactly this situation)?

Sorry, I don't understand! Parents=ParentID is on client or server?

When I request a Parent from the client:

  GET /ModelRoot/TableParents    ->    {"ID":1,"ID":2,...}

  GET /ModelRoot/TableParents/1    ->     {"ParentDescription":"This is a parent",{???}}

How mORMot expose multiple TableChild ID in the body of the response?

To add a new Child with a reference to the Parent what I need to do:

  POST /ModelRoot/TableChilds&ParentID=1    -> {"ChildDescription":"This is a child"}

  POST /ModelRoot/TableChilds        -> {"ParentID":1,"ChildDescription":"This is a child"}

Do you need it for some AJAX properties?

I'm just trying to simplyfing the client logic: as I don't understand the server side too! smile
I don't need a Delphi client, just remote apps (Javascript/PHP/Python/Ruby/etc.)  that talks with a mORMot server and viceversa.

> I do not remember that such a REST routing is standard - is it?

I've read about this in a lot of docs, this is an example:

REST API Design Rulebook - O'Reilly:
http://books.google.it/books?id=eABpzyT … &q&f=false

Ruby on Rails implement this.

But I just want to go in the mORMot way, if I'll find it! smile

Thanks for your help!
Mauro

#5 mORMot 1 » one-to-many and REST POST Method » 2012-11-13 00:02:05

sytis
Replies: 8

Hi,
I'm studying mORMot and Delphi: actualy I have some problem with Object relations and http REST.

Basically I'm trying to understand how to create a one-to-many relationship between two objects:

Type
  TSQLTableParents  = Class(TSQLRecord)
  public
    fDescription: RawUTF8;
  published
    property Description: RawUTF8 read fDescription write fDescription;
  End;

  TSQLTableChild = Class(TSQLRecord)
  public
    fChildDescription: RawUTF8;
    fParents: TSQLTableParents;
  published
    property ChildDescription: RawUTF8          read fChildDescription write fChildDescription;
    property Parents:          TSQLTableParents read fParents          write fParents;
  End;

With this Parents property it's possible to do something like this from a client via REST/http:

POST /ModelRoot/TableParents/1/TableChild -> {"ChildDescription":"This is a child"}

GET /ModelRoot/TableParents/1/TableChild  -> {"ID":13,"ID":51,...}

Thanks,
Mauro

#6 Re: mORMot 1 » How to test VirtualTableExternalRegisterAll » 2012-10-25 09:06:33

It's a CONSOLE application so when you compile it with the second VirtualTableRegister activated the program crash and close the window.
The exact error message is:

Project Project1.exe raised exception class C0000005 with message 'access violation at 0x00403dba: read of address 0xbaadf00d'.
Process stopped. Use Step or Run to continue.

Here the test source I'm using:

------------------------Project1.dpr----------------------

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  SynCommons,
  SynOleDB,
  SynDB,
  SQLite3Commons,
  SQLite3,
  SQLite3DB,
  SQLite3HttpServer,
  Unit1 in 'Unit1.pas';

Var
  aModel : TSQLModel;
  aServer : TSQLRestServerDB;
  Server: TSQLite3HttpServer;
begin
  aModel := CreateMyModel;

  // The program compile and run correctly if you
  // comment out one of these lines
  aModel.VirtualTableRegister(TSQLA, TSQLVirtualTableJSON);
  aModel.VirtualTableRegister(TSQLB, TSQLVirtualTableJSON);

  aServer := TSQLRestServerDB.Create(aModel,'database.db3',false);

  aServer.CreateMissingTables();

  Server := TSQLite3HttpServer.Create('8080',[aServer]);
  WriteLn('Press ENTER to Exit');
  ReadLn;
end.

-----------------Unit1.pas-----------------------
unit Unit1;

interface

uses
  SynCommons,
  SQLite3Commons;

type
  TSQLA = class(TSQLRecord)
  private
    fFirstField : Integer;
    fSecondField: RawUTF8;
  published
    property FirstField: Integer  read fFirstField  write fFirstField;
    property SecondField: RawUTF8 read fSecondField write fSecondField;
  end;

type
  TSQLB = class(TSQLRecord)
  private
    fThirdField : Integer;
    fFourthField: RawUTF8;
  published
    property ThirdField: Integer  read fThirdField  write fThirdField;
    property FourthField: RawUTF8 read fFourthField write fFourthField;
  end;

function CreateMyModel: TSQLModel;

implementation

function CreateMyModel: TSQLModel;
begin
  result := TSQLModel.Create([TSQLA, TSQLB]);
end;

end.

#7 Re: mORMot 1 » How to test VirtualTableExternalRegisterAll » 2012-10-24 14:51:52

I can't understand how use VirtualTableExternal (with just one table, internal or external, everything works as expected).

This sample code doesn't work rising "exception class C0000005 with message: 'access violation at 0x0403dba...":

Var
aModel : TSQLModel;
aServer : TSQLRestServerDB;
aProps : TOleDBConnectionProperties;
//vRecord1 : TSQLA;
//vRecord2 : TSQLB;

begin
aModel : CreateTestData;
aModel.VirtualTableRegister(TSQLA, TSQLVirtualTableJSON);
aModel.VirtualTableRegister(TSQLB, TSQLVirtualTableJSON);
aServer : TSQLRestServerDB.Create(aModel,'db.db3',false);
aServer.CreateMissingTables();
TSQLite3HttpServer.Create('8080',[aServer]);
WriteLn('Press ENTER to Exit');
ReadLn;
end.

//---------------------------- interface file

type
TSQLA = class(TSQLRecordVirtualTableAutoID)
private
   ffield1: Integer;
   ffield2: RawUTF8;
published
   property field1: Integer read ffield1 write ffield1;
   property field2: RawUTF8 read ffield2 write ffield2;
end;

type
TSQLB = class(TSQLRecordVirtualTableAutoID)
private
   ffield3: Integer;
   ffield4: RawUTF8;
published
   property field3: Integer read ffield3 write ffield3;
   property field4: RawUTF8 read ffield4 write ffield4;
end;
function CreateTestData: TSQLModel;
implementation
function CreateTestData: TSQLModel;
begin
result : TSQLModel.Create([TSQLA, TSQLB], 'root');
end;

Thanks for your help!

#8 mORMot 1 » How to test VirtualTableExternalRegisterAll » 2012-10-23 13:29:40

sytis
Replies: 4

I'm using the current source code for new VirtualTableExternalRegisterAll.

Right now I'm able to connect to MSSQL db server with a registered
VirtualTableExternal.
What I can't understand is how to register more than one external table
in the same Model to be able to use VirtualTableExternalRegisterAll.

Thanks!
Mauro

#9 Re: mORMot 1 » 04 - HTTP Client-Server Error 403 Forbidden » 2012-10-22 05:33:22

Thanks it worked!
After reading “1.4.4.1.3. Authentication” in http://synopse.info/files/pdf/Synopse%2 … 201.17.pdf mORMot REST authentication is more clear to me now!

I think that the current “1.4.3.1.2.3. REST and JSON” example in the same doc it’s not correct because it doesn’t mention authentication at all.

Mauro

#10 Re: mORMot 1 » 04 - HTTP Client-Server Error 403 Forbidden » 2012-10-18 15:45:34

OK!
as for Version 1.16
-- added authentication to the remote process

In the client I see this login/pwd: User / synopse

but from RESTclient using Basic Authentication I'm facing the same error...

How can I disable aHandleUserAuthentication in the server just to test the connection?

#11 mORMot 1 » 04 - HTTP Client-Server Error 403 Forbidden » 2012-10-18 14:25:17

sytis
Replies: 4

Hi!
I'm new to Delphi and mORMot...

I'm trying samples and everything seems to work as expected.

After some data insert from Project4Client.exe I try to GET some data from RESTclient/browser

10.0.0.100:8080/root
10.0.0.100:8080/root/SampleRecord
10.0.0.100:8080/root/SampleRecord/1

But I get this error instead of JSON data:

{
   "ErrorCode":"403",
   "ErrorText": "Forbidden"
}

There is some authentication to setup in the browser? I'm doing something wrong?

I'm using Delphi7/RAD Studio XE2 with the same result.

Thanks!
Mauro

Board footer

Powered by FluxBB