Hi,
I'm revisiting my RESTServer using only the server side components you will continue to provide/support. (I will miss LoadBalancer. But there's a way to replace it.)
I want to be sure I use the right components as they should.
I reduced my server to a few rtcHTTPServer and a lot of rtcDataProvider.
I replaced client side components and removed remote functions.
I want to keep the excellent performance I have today, but using only the components you will support.
For example: I have the Authorization dataProvider that will handle authorization method and connect to a database to check user and password.
Another dataProvider to handle Synchronous and Asynchronous requests. My Sync request would take at most 2s to complete (database queries).
My Async request will spawn a thread, and return immediately.
Here are a few code examples.
I create one of the servers as shown below
fWebAPIServer := TRtcHttpServer.New;
fWebAPIServer.Name := 'webAPIserver';
fWebAPIServer.Tag := 0;
fWebAPIServer.MultiThreaded := True;
fWebAPIServer.Blocking := False;
fWebAPIServer.RestartOn.ListenLost := True;
fWebAPIServer.OnListenStart := event_WebAPIServer_OnListenStart;
fWebAPIServer.OnListenStop := event_WebAPIServer_OnListenStop;
fWebAPIServer.OnListenLost := event_WebAPIServer_OnListenLost;
fWebAPIServer.OnListenError := event_WebAPIServer_OnListenError;
My login DataProvider looks like this:
procedure TWSWebLoginAPIHandler.DoEvent_CheckRequest(aSender: TRtcConnection);
var
lUserSession : TcoreWebServerWebSession;
lData : TRtcDataServer;
lAuthRequest,
lPassword : String;
lMainSQLConnection : IcoreSQLConnection; // Usado para buscar usuario e senha!
lAuthorized : Boolean;
begin
lData := TRtcDataServer(aSender);
lAuthorized := lData.FindSession( lData.Request.Cookie['session']);
if not lAuthorized then
begin
// verificação de credenciais.
// Temos que diferencar entre credenciais do internas e externas.
lUserSession := TcoreWebServerWebSession.Create;
lAuthRequest := lData.Request['Authorization'];
fAuthorization.ParseAuthRequest( lAuthRequest,
lUserSession.Authentication.&Type,
lUserSession.Authentication.AuthUserName,
lUserSession.Authentication.AuthCode,
lUserSession.Authentication.AuthPassword,
lUserSession.Authentication.AuthToken );
lMainSQLConnection := glbSQLConnectionFactoryManager.MainConnection.AcquireConnection;
lMainSQLConnection.GetLoginPassword( lUserSession.Authentication.AuthUserName,
lUserSession.Authentication.AuthCode,
lUserSession.Authentication.AuthUserID,
lPassword );
lAuthorized := DoCheckAuthorization( lUserSession.Authentication.&Type,
lUserSession.Authentication.AuthUserName,
lUserSession.Authentication.AuthCode,
lUserSession.Authentication.AuthPassword,
lUserSession.Authentication.AuthToken,
lPassword);
if lAuthorized then begin
lData.OpenSession;
lData.Response.Cookie['session'] := lData.Session.ID;
lData.Session.asObj['sessiondata'] := lUserSession;
lData.Accept;
end;
end;
end;
Would this structure block requests in any way? I don't want to block incoming user requests while processing data. For example, one user might be downloading a large file while another is attempting to upload a few images.
Is this the correct way to work with those classes.
Would the above code be easier to migrate to v10?
Best regards,
Clément