Skip to content
Luca Minuti edited this page Jun 28, 2018 · 4 revisions

Basic configuration

A WiRL application is basically an HTTP server with a routing system that follows 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>

Engines

Every WiRL server should have at last one engine. An engine is an object that knows what to do with an HTTP request. WiRL offers three engines: TWiRLEngine is the basic engine that handles ReST request, TWiRLFileSystemEngine is capable of server static files and TWiRLhttpEngine provides an OnExecute event where the developer can handle the request.

Applications

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 syntaxes, the first is for compatibility with the older version of Delphi.

Security

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.

Clone this wiki locally