You are not logged in.
Pages: 1
Hello,
Some background: I work on an existing client-server software and I'd like to extract the database part to expose objects via a RESTful server. I'm evaluating various library (Datasnap, DataAbstract, mORMot, ...) to pick the right one for the job. So far mORMot seems incredible, but I had a question I did not find an answer to in the documentation.
As the database is quite complex and will not properly map to an ORM (tables & fields have prefix, I need more control server-side for locking, ...) I wanted to use interface-based services. It works beautifully, but unfortunately not in a CRUD way.
I was wondering if it's possible to use CRUD by registering hooks.
Ideally I'd like to register objects quite like I register services (ServiceRegister(TObjectA, [TypeInfo(IObjectA)], sicShared);), have mORMot handle the CRUD/REST parsing, and have a function get called with the eventual JSON data provided by the client and the method (GET, POST, ...). My function would return a JSON serialized string (or record).
Is it possible or do I have to use the integrated ORM feature to have a proper REST addressable server (or am I completely in the wrong and should not build the server like that)?
Offline
Bonjour,
I've read the documentation more carefully and was able to attain what I was hoping for by subclassing the TSQLRestServer class and implementing EngineRetrieve/List/Add/...
Is it the proper way to do it? Any pitfall I should be aware of?
This is indeed a superb library, I've made a donation to thank you for your work.
Offline
If you use method-based services, you will have direct access to the HTTP verbs, so will be able to implement your work easier, I suspect.
See the corresponding chapter of the SAD 1.18 pdf.
I would not subclass TSQLRestServer for this.
Too much overkilled, IMHO.
Sub-classing is only needed to implement a whole database access, e.g. for in-memory TObjectList-based storage, or even mORMotDB.pas for external SQL databases direct access.
Offline
Hello,
Thank you for the tip. I've tried to implement a proof-of-concept and can indeed access verbs easily.
I had one question related to marshalling the result however. For now I'm working with a class derived from TSQLRecord with a few published properties. Is there a better way to return the result (through Ctxt.Result) than by doing a ObjectToJSON(myClass)?
Will it work with UrlDecodeObject you mention in the SAD (15.3) or should I use something else to unmarshall the returned value?
Offline
Take a look at the newly introduced TDocVariant.
http://blog.synopse.info/post/2014/02/2 … riant-type
Can be pretty easy to work with, and return directly any JSON data.
Offline
Pages: 1