-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
A WiRL application is basically an HTTP server with a routing system that follow the ReST specification. The core of the application is the Engine that handles all the HTTP requests and sends each one to the right sub-module called Application. Each application has its own resources and filters used to process the requests.
The following example shows a basic configuration:
begin
// Create http server
FServer := TWiRLhttpServer.Create(nil);
// Server configuration
FServer
.SetPort(8080)
.SetThreadPoolSize(5)
// Engine configuration
.AddEngine<TWiRLEngine>('/rest')
.SetEngineName('WiRL Demo')
// Main application configuration
.AddApplication('/app')
.SetAppName('Default App')
.SetResources('*')
.SetFilters('*')
;
FServer.Active := True;
end;This configuration defines an application that answers to URLs like this:
http://localhost:8080/rest/app/<resource_path>
Every WiRL server should have at last one engine. An engine is an object that know what to do with an HTTP request. WiRL offers three engine: TWiRLEngine is the basic engine that handle ReST request, TWiRLFileSystemEngine is capable of server static files and TWiRLhttpEngine provides an OnExecute event where the developer can handle the request.
The WiRL engine can handle many sub-applications, each application can have different resources, filters and authentication systems but they can also be shared.
Let's try with an example:
begin
// ...
// First application
FEngine.AddApplication('/auth')
.SetName('Autentication Module')
.SetResources('Server.Auth.TAuthResource,Server.Audit.TMonitorResource')
;
// Second application
FEngine.AddApplication('/order')
.SetName('Order Module')
.SetResources([
'Server.Order.TOrderResource',
'Server.Order.TCustomerResource',
'Server.Audit.TMonitorResource'])
;
// ...
end;In this example we configure two applications, the first handles two resources: TAuthResource and TMonitorResource the second three resources: TOrderResource, TCustomerResource and TMonitorResource. As you can see the TMonitorResource is used by both applications. You can notice that the SetResources method has two different syntax, the first is for compatibility with the older version of Delphi.
The TWiRLApplication class has some configuration options used during the authentication process. These are:
- Secret: the secret key of the JWT token
- AuthChallengeHeader: the HTTP header used during the authentication challenge
- TokenLocation: the JWT token location (Bearer, Cookie, Header)
- TokenCustomHeader: if the JWT is in a custom header you can specify which one
- ClaimClass: the class that has all the custom JWT claims
If you need more information about standard WiRL authentication you can read the Authentication and Authorization page.