Skip to content

Working with URL patterns

Michael Justin edited this page May 18, 2025 · 5 revisions

Mapping types

Exact Mapping:

Examples: /index.html, /report.csv, /admin, /download

Path-Based Mapping with Wildcards:

Using /* after a path, like /products/*, means any request to the /products path and its sub-paths will be mapped to the web component.

Examples: /*, /admin/*

Extension-Based Mapping:

Mapping with *.page (or any other extension) allows the web component to handle requests for all resources ending with that extension. For example, *.html can be used to handle HTML pages.

Code example

From unit tests:

procedure TAPIConfigTests.TestRegisterTwoMappings;
var
  Server: TdjServer;
  Context: TdjWebAppContext;
begin
  Server := TdjServer.Create;
  try
    Context := TdjWebAppContext.Create('example');
    Context.Add(TExamplePage, '/index.html');
    Context.Add(TExamplePage, '*.txt');
    Server.Add(Context);
    Server.Start;

    CheckGETResponseEquals('example', '/example/index.html');
    CheckGETResponseEquals('example', '/example/test.txt');
  finally
    Server.Free;
  end;
end;
Clone this wiki locally