HTTP Layer
HTTP request/response runtime, middleware pipeline, dispatch handlers a error rendering flow.
Overview
HTTP runtime is built on PSR-7, PSR-15 and PSR-17. Request/response handling stays on PSR interfaces from entrypoint to emitter.
Request lifecycle
Request lifecycle in current runtime model:
public/index.php
-> Kernel::handle()
-> ServerRequest from globals
-> Kernel::run()
-> Kernel::bootstrap()
-> Framework::run()
-> MiddlewareStack
-> MiddlewareResolver
-> MiddlewarePipeline
-> DispatchRequestHandler
-> Router / route match
-> route middleware
-> ControllerResolver
-> ResponseInterface
-> ResponseEmitter
PSR interfaces
PSR-7 represents request/response (ServerRequestInterface, ResponseInterface). PSR-15 drives middleware and request handlers (MiddlewareInterface, RequestHandlerInterface). PSR-17 factories are registered in core provider and used during dispatch and controller context initialization. PSR-18 HTTP client is optional and provided by dedicated HTTP client providers.
Request handling
Kernel creates request from globals when handle() receives no explicit request. Framework::run() then executes global middleware pipeline with DispatchRequestHandler as fallback handler.
<?php
declare(strict_types=1);
use Lemonade\Framework\Core\Context\ApplicationContextFactory;
use Lemonade\Framework\Core\KernelFactory;
require __DIR__ . '/vendor/autoload.php';
$context = (new ApplicationContextFactory())->fromGlobals(__DIR__);
(new KernelFactory())->create($context)->handle();
Responses
Controller actions may return ResponseInterface directly, or scalar/stringable/null values. ControllerResolver normalizes scalar/stringable/null results to HTTP 200 HTML response.
public function api(): ResponseInterface
{
return $this->json(['ok' => true], 200);
}
public function page(): string
{
return '<h1>Hello</h1>';
}
public function redirectToHome(): ResponseInterface
{
return $this->redirect('/');
}
Controller helpers
Base controller provides response helpers backed by PSR factories: text(), html(), json(), redirect(), download(), response(), stream().
Middleware
Global middleware is configured through MiddlewareStack and resolved by MiddlewareResolver from class definitions to container instances. Route middleware is resolved inside DispatchRequestHandler from matched route metadata and wraps controller request handler.
Controller dispatch
DispatchRequestHandler performs route matching and creates ControllerRequestHandler. ControllerResolver resolves controller via container, injects request context, resolves action params (including route params and optional ServerRequestInterface) and normalizes action result to ResponseInterface.
Emission
ResponseEmitter is terminal HTTP step: sets status code, sends headers, and streams PSR response body to output.