You are not logged in.
Pages: 1
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
Offline
No, it is not possible as this.
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.
Do you need it for some AJAX properties?
I do not remember that such a REST routing is standard - is it?
Offline
> 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!
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!
Thanks for your help!
Mauro
Offline
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
Offline
:) 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
Offline
There is no link between interface-based services and ORM classes, at REST URL routing level.
I suspect it will be confusing:
1. For interface-based services, just put the TSQLRecord instance as a parameter.
2. Which method of the interface is to be executed?
You have such a routing only for method-based services.
Offline
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
Offline
For method-based services do you mean ModelRoot/TableName/ID/MethodName? This is what I'm trying to do. right now...
Yes, it can work like this.
See TSQLRestServerCallBackParams.Context.Table and TSQLRestServerCallBackParams.Context.ID and TSQLRestServerCallBackParams.URI.
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?
Of course it is.
Method-based services can do it directly.
It would be possible to develop a resource only mORMot server (/ModelRoot/TableName/ID/AnotherTableName/ID...)?
It would be possible, but it is not on the roadmap.
mORMot provides basic RESTful API, not such over-sophisticated URI routing.
Offline
Pages: 1