Skip to main content

Route Integration

Routes are defined as a static configuration array. Instead of passing an anonymous function, Archibald uses a String Handler pattern to link a route to a controller method.

How to use

// Route Configuration
{
method: RouteMethod.GET,
path: '/users/address',
handler: 'AccountController.getAddress' // Links to the registered instance
}

Under the Hood: String Resolution

When registerRoute encounters a string handler, it performs the following logic:

  1. Parsing: Splits the string by . to identify the controller key and the method name (e.g., ['AccountController', 'getAddress']).
  2. Lookup: Retrieves the controller instance from the internal controllers Map.
  3. Binding: Wraps the method call in a Hapi handler and uses .bind(controller). This is critical as it ensures that this inside the controller method correctly points to the controller instance, allowing access to its @Inject()ed services.

The Wiring Flow Diagram