#1 2015-10-22 10:35:38

knight_killer
Member
Registered: 2011-11-18
Posts: 4

REST backend

I new to mORMot and I am trying to create a REST backend for a Single Page Application (AngularJS or EmberJS).

The main requirements of this backend are:
#1 make existing NexusDB Tables dynamically available as REST resources, that the JS frontend can access the Data with the standard HTTP methods
#2 we need to be able to define some Resources, that are not Tables but methods.
#3 Authorization based on user and REST resource / HTTP method
#4 deliver static Files (index.html, assets) - index.html should be default for root access http://1.2.3.4:8080/
#5 SSL

I started with THTTPApiServer, then I noticed, that I need a TSQLRestServer too for the Requirement #1. But then I need to define a static Model. I think TSQLDBServerHTTPApi and TSQLDBNexusDBConnection is not possible, because then I can't use REST, but only SQL-Queries.

Is there a possibility to generate a dynamic Model from existing Databases using TSQLDBNexusDBConnection or do you have an other idea for the requirements above?

#2 is no Problem (I think), just add some published Methods to a TSQLRestServer.
#3 depends on #1, but I think that should be easy
#4 I found this thread http://synopse.info/forum/viewtopic.php?id=2033
#5 easy

Thanks for pushing me in the right direction,
Roman

Offline

#2 2015-10-22 16:07:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,242
Website

Re: REST backend

IMHO THTTPApiServer is very low-level, and you would not benefit of most of the framework.

I guess you may use method-based services also for tables, returning the JSON result of your NexusDB requests (via TSQLDBNexusDBConnection) directly the the client.

Other points seem just fine.

Offline

#3 2015-10-23 08:56:48

knight_killer
Member
Registered: 2011-11-18
Posts: 4

Re: REST backend

Thank you Arnaud

I thought I need a THTTPApiServer on top of one (or more) TSQLRestServer. I'm glad, if I don't need it.

After reading a lot of the Documentation and Code, I think I have to derive a own Server Class directly from TSQLRestServer and use a TSQLRestStorageExternal for it. Then I try to dynamically generate a Model from the existing Nexus Tables and add some custom method-based services (modular via a factory).

If that does not work (particularly the dynamic Model) I will use method-based services for the Nexus Tables as well.

Is it possible to add service methods dynamically without having them statically in published part of the RestServer?

Thanks
Roman

Offline

#4 2015-10-23 09:06:52

knight_killer
Member
Registered: 2011-11-18
Posts: 4

Re: REST backend

knight_killer wrote:

Is it possible to add service methods dynamically without having them statically in published part of the RestServer?

Never mind. I found TSQLRestServer.ServiceMethodRegister()


Edit:

knight_killer wrote:

I thought I need a THTTPApiServer on top of one (or more) TSQLRestServer.

Ah, i mixed up THTTPApiServer with TSQLHttpServer. I don't need a THTTPApiServer, but a TSQLHttpServer and some TSQLRestServers (one for Nexus, one for custom service methods and one for static files like index.html)

Last edited by knight_killer (2015-10-23 12:24:19)

Offline

Board footer

Powered by FluxBB