#1 2017-04-29 08:13:17

rcyboom
Member
Registered: 2017-04-29
Posts: 7

What is the difference between TSQLRestServer and TSQLHttpServer?

I am a newbie, these days I have been reading documents and forums.
There is a problem has been bothering me for a long time, would like to ask about.
What is the difference between TSQLRestServer and TSQLHttpServer?
I think TSQLHttpServer mainly provides http protocol communication and control, TSQLRestServer is mainly to provide database-based REST services.
Then, the document has a reference to the Publishing a service on the server, I understand that the addition of a REST method.
But for the benefit and limitations of this implementation, ,the interface is for public service on the server and the client.
So, can I add a Sum method to the TSQLHttpServer ? do not increase the method in TSQLRestServer to achieve the purpose of it?
Or that can only  overwrite its OnRequest method and analysis the URL to do?Such as Project04ServerStatic.
Very sorry for my English, which is translated with google.:D

Last edited by rcyboom (2017-04-29 08:17:36)

Offline

#2 2017-04-29 08:28:35

rcyboom
Member
Registered: 2017-04-29
Posts: 7

Re: What is the difference between TSQLRestServer and TSQLHttpServer?

If i want to add a method name of Pow(integer x;integer y):integer.
I can add it in TSQLRestServerCustom(TSQLRestServer ),or add it in OnRequest of TSQLHttpServerCustom(TSQLHttpServer).
I don't know where is the different?
tks.

Offline

#3 2017-04-29 11:01:53

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: What is the difference between TSQLRestServer and TSQLHttpServer?

> If i want to add a method name of Pow(integer x;integer y):integer.
> I can add it in TSQLRestServerCustom(TSQLRestServer ),or add it in OnRequest of TSQLHttpServerCustom(TSQLHttpServer).
> I don't know where is the different?

You can use both, with Request approach you have a bit more low level approach which also means more work involved. If for example you have 10 functions you're server publishes/implements, Pow, Round, Sum, Arc... you can handle them all inside Request but you'll have to manually determine which one is called based on URI. With method based approach you would declare all 10 of them as individual methods and engine itself will do lot of pre work for you so it's easier to implement your business logic. Take a look at differences inside Samples4 and Samples6 for example of the two approaches.
There is also a third approach, kind of highest level, that's using interfaces. You can use methods on server as regular local functions, take a look at Sample14, also in docs there's a chapter for it.

Offline

#4 2017-04-29 16:11:34

rcyboom
Member
Registered: 2017-04-29
Posts: 7

Re: What is the difference between TSQLRestServer and TSQLHttpServer?

tks,I know. but maybe I want to ask is :
TSQLRestServer can also provide HTTP services alone, and don't need TSQLHttpServer?
oh....
maybe i want to know if they have any connection or difference.
I think it's very important for a newbie.
Thanks again~

Offline

#5 2017-04-30 11:42:55

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: What is the difference between TSQLRestServer and TSQLHttpServer?

> TSQLRestServer can also provide HTTP services alone, and don't need TSQLHttpServer?
> maybe i want to know if they have any connection or difference.

No, TSQLRestServer is about implementing your business logic, while SQLHttpServer is about transporting data from Client to Server.

You should have your business written with help of  one of RestServer descendants  (take a look at section 11.1.1. in docs), after that comes question how to make that RestServer available to clients, or how to publish it.
It's usually through TCP/IP (TSQLHttpServer for example), but you can also have local access (both client and server are on local machine) established with pipes or windows messages. Take a look at 11.2, 11.3, 11.4 section in docs.

Offline

#6 2017-04-30 17:47:56

rcyboom
Member
Registered: 2017-04-29
Posts: 7

Re: What is the difference between TSQLRestServer and TSQLHttpServer?

igors233 wrote:

> TSQLRestServer can also provide HTTP services alone, and don't need TSQLHttpServer?
> maybe i want to know if they have any connection or difference.

No, TSQLRestServer is about implementing your business logic, while SQLHttpServer is about transporting data from Client to Server.

You should have your business written with help of  one of RestServer descendants  (take a look at section 11.1.1. in docs), after that comes question how to make that RestServer available to clients, or how to publish it.
It's usually through TCP/IP (TSQLHttpServer for example), but you can also have local access (both client and server are on local machine) established with pipes or windows messages. Take a look at 11.2, 11.3, 11.4 section in docs.


Thank you very much.
I've started using mORMot to write code.
I've been reading documents and forums these days.
At the moment I have a problem, I added a add method, created by Interface, and has been properly registered.
But when I visited with a browser, I still went wrong:
{
"ErrorCode": 400,
"ErrorText": "Bad Request""
}
I'm sure I will set the permissions for httpserver and restserver to none.
And I can get the static files I need in httpserver's Request.
Part of the code is as follows:

the Interface unit and TSQLUserRecord unit is the same as  document.
I know I may have asked a stupid question, but as a beginner, what I need most now is my  demo to run properly, and then I can do all the functions on it!

Last edited by rcyboom (2017-04-30 18:40:57)

Offline

#7 2017-04-30 17:51:58

rcyboom
Member
Registered: 2017-04-29
Posts: 7

Re: What is the difference between TSQLRestServer and TSQLHttpServer?

In the browser:
Http://localhost:8888/web/index.html
Is ok!
Http://localhost:8888/api/add? A=2&b=322
Will get error code 400. ROOT_NAME='API'.

Offline

#8 2017-04-30 18:08:57

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

Re: What is the difference between TSQLRestServer and TSQLHttpServer?

Please follow the forum rules, and don't put full extend of code within the forum posts.
See rule #7 in https://synopse.info/forum/misc.php?action=rules
smile

The doc is clear about the interface-based service routing.
You should try URI localhost:8888/api/methods/add or localhost:8888/api/methods.add

Offline

#9 2017-04-30 18:39:58

rcyboom
Member
Registered: 2017-04-29
Posts: 7

Re: What is the difference between TSQLRestServer and TSQLHttpServer?

Thank you very much. Thanks again!
I finally got the right result:
{"result": [5]}
At the same time, I had read this rules, I am sorry, I will delete this code, and then go to bed.
Finally I can sleep, only 3 hours on the sun will come out... ...
Thanks ~

Offline

Board footer

Powered by FluxBB