#1 2016-11-28 15:41:03

kifah
Member
Registered: 2016-11-28
Posts: 10

Create REST web service

Hi,
I downloaded today mORMot Framework, and I run a small rest server sample as following

program Synopse_mORMot_Console;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  SynCommons,
  SynDBOracle,
  mORMot,
  mORMotHttpServer;

type
  TServiceServer = class(TSQLRestServerFullMemory)
  published
    function HelloWorld(Ctxt: TSQLRestServerURIContext):Integer;
  end;

{ TServiceServer }
function TServiceServer.HelloWorld(Ctxt: TSQLRestServerURIContext): Integer;
begin
  Ctxt.Results(['kifah', 'najem', 10, date]);
  result := 200; // success
end;

var
  Model: TSQLModel;
  Service: TServiceServer;
  Server: TSQLHttpServer;
begin
  try
    Model := TSQLModel.Create([], 'service');
    Service := TServiceServer.Create(Model);
    Service.NoAJAXJSON := false;

    Server := TSQLHttpServer.Create('8080',[Service], '+', useHttpApiRegisteringURI);
    Server.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries


    writeln('Server is running.'#10);
    write('Press [Enter] to close the server.');
    readln;

    Server.Free;
    Service.Free;
    Model.Free;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

I want to create a REST web service,
      1. which will be use by other developers
      2. iOS, Android, ASPX as well as delphi application
      3. there will be thousands of users using it at the same time
      4. the database is oracle and\or ms sql,
      5. some result from the web  service will be some hundreds of records each record about 12 fields (string, number, datetime)

so I check the sample code you place in the sample folder, but they are not clear to me.
So how to start, I read that you support http.sys which is very fast and stable, but it dose not work as ISAPI.
shall I create a consol appliction which remain runing on the server and put it on server startup, or create a windows service, or ISAPI

Please can you lead me and suggest for the first steps

Offline

#2 2016-11-28 16:18:58

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

Re: Create REST web service

The easiest is to use an interface-based service, and not a method-based service.
Define your record with 12 fields, and return it as an array from your service method.

About hosting, http.sys is in fact used by IIS, without the overhead of IIS.
The easiest is to create a Windows Service.
You can run the same mORMot server as service or console app.

Offline

#3 2016-11-29 06:56:15

kifah
Member
Registered: 2016-11-28
Posts: 10

Re: Create REST web service

Hi,

Thank you very much....

Which is better to make the web service to run as ISAPI or as a windows service, please advise knowing there will be too many connections.

for the interface-based service and method-based service, can you please provide a sample I can start with.

Actually I am new to web service.

Offline

#4 2016-11-29 07:55:22

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

Re: Create REST web service

ISAPI has an overhead, since it runs within IIS.
Whereas a service using mORMot will directly work with http.sys API.

See samples 14, 16, 20 and 31.

I'm still working on a SOA MVC sample more close to reality.

Offline

#5 2016-11-29 09:34:55

kifah
Member
Registered: 2016-11-28
Posts: 10

Re: Create REST web service

Hi,

Sorry for disturbing you again wink

So you advise me to use windows service instead of the IIS....
as well is the sample I posted above is a good for web service which will handle many connections, or you advise better approach...
Please if there is a small sample just to start, as well showing how to pass parameters and results between server and client, knowing that client and server might send too much data

Offline

#6 2016-11-29 10:26:28

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

Re: Create REST web service

useHttpApiRegisteringURI will make a http.sys server, so will easily handle 50,000 concurrent connections. wink

Take a look at the samples I wrote about, and the documentation FAQ.
http://synopse.info/files/html/Synopse% … l#TITL_123

Offline

#7 2016-11-29 14:19:28

kifah
Member
Registered: 2016-11-28
Posts: 10

Re: Create REST web service

Hi,

Please can you tell me bellow sample code is good for the web service

as well please I need to know how to make this as ISAPI to run under IIS, since our company requirements to use IIS....
and when it is under IIS, how to call the URI...
now I am using http://mycomany/api/helloworld and the parameters within body.

again thank you very much for your support

Last edited by kifah (2016-11-30 04:25:19)

Offline

#8 2016-11-29 16:43:05

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

Re: Create REST web service

Please stop pasting some code in the forum.
It is not readable.
As stated by the rules, use a pastebin like service.
http://synopse.info/forum/misc.php?action=rules

Offline

#9 2016-11-30 04:26:40

kifah
Member
Registered: 2016-11-28
Posts: 10

Re: Create REST web service

Hi,

Sorry, I deleted the code.

Please I still have no answer of what I asked you, I tried to get information from your documentation and sample but it is not clear

Offline

#10 2016-12-04 15:21:21

kifah
Member
Registered: 2016-11-28
Posts: 10

Re: Create REST web service

Hi,

can use your framework to make ISAPI

Offline

#11 2016-12-04 16:06:13

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

Re: Create REST web service

There is no point of hosting a mORMot server in ISAPI.
You should rather run the mORMot server as a stand-alone service.

If needed, you can share the mORMot server with an IIS server on the same PC.
But it is of little need:
- both are based on the same http.sys high-performance server
- but IIS has a bigger overhead, and is more difficult to setup/tune
- the mORMot server can serve any static content directly
- you are not stuck with IIS/Windows, and can switch to Linux if needed

Offline

#12 2016-12-04 16:15:25

kifah
Member
Registered: 2016-11-28
Posts: 10

Re: Create REST web service

Hi,

Dose this mean I can sue the same port like (80) for both, as well in IIS there is full logging for all actions and request management, dose mORMot support those 2.... is there a new update that mORMot will run through IIS

Offline

#13 2016-12-04 16:16:28

kifah
Member
Registered: 2016-11-28
Posts: 10

Re: Create REST web service

Sorry, again, how to create a linux rest server using mORMot

Offline

#14 2016-12-04 17:29:56

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

Re: Create REST web service

With http.sys, you can share the same port for both, but register each sub-URI.
You can enable logs, using HTTP API 2.0, also for mORMot servers.
See the doc.
There won't be any update running mORMot through IIS, since it is not needed.

Compile the mORMot server using FPC for Linux, then run on Linux.

Offline

#15 2016-12-05 08:36:01

kifah
Member
Registered: 2016-11-28
Posts: 10

Re: Create REST web service

Hi,

Thank you very much for your support.
Please do you have a support plans I can purchase.
Actually I am doing a project to create REST web services, and I am new to web services... all my experience was DCOM and normal application, and I will need support creating my web services as following

1. activating\enabling the logs using HTTP API
2. what is the best structure to use and what component to use to make the service robust
3. what if the service stop responding, what an alternatives
4. can I run multiple windows services (rest web service) all share teh same port, so user can sue http://www.mydomain.com/service1/auth for first window service and http://www.mydomain.com/service2/getemployee for second window services
and some other points
Regards

Last edited by kifah (2016-12-05 14:45:13)

Offline

Board footer

Powered by FluxBB