The application starts by creating an ApivalkConfiguration object. This configuration requires a Router and can optionally include a Renderer, an ExceptionHandler, and a PSR-11 Container. The Apivalk instance is then initialized with this configuration.
Calling $apivalk->run() initiates the request processing. If an ExceptionHandler was configured, it is registered at this stage to catch any unhandled exceptions during the lifecycle.
The final step in the middleware pipeline is the execution of the Controller itself. Since all Apivalk controllers implement __invoke(), they are called with the populated Request object. The controller executes the business logic and MUST return an AbstractApivalkResponse.
The response returned by the middleware stack is passed back to the run() method, which returns it to the caller (e.g., your index.php). The developer then typically uses the configured Renderer to:
Set the HTTP status code.
Send the necessary HTTP headers (including Content-Type: application/json).
Serialize the response data (and optional pagination info) to JSON and output it.