Home

PSR15

PSR-15, the PHP Standard Recommendation for HTTP Server Request Handlers, is a specification that standardizes server-side HTTP middleware and request handlers in PHP applications. It defines interfaces that allow middleware components to be composed into a request-handling pipeline and to interoperate across frameworks and libraries.

The core interfaces are Psr\Http\Server\MiddlewareInterface and Psr\Http\Server\RequestHandlerInterface. MiddlewareInterface defines a single method, process(ServerRequestInterface $request, RequestHandlerInterface

Usage within a pipeline is straightforward: a middleware component implements MiddlewareInterface and can either return a

Impact and ecosystem: PSR-15 provides a common contract that enables middleware reuse across frameworks. It is

Relation to other standards: PSR-15 complements PSR-7 for HTTP message objects and PSR-17 for factories. It does

$handler):
ResponseInterface.
RequestHandlerInterface
defines
handle(ServerRequestInterface
$request):
ResponseInterface.
Both
interfaces
rely
on
PSR-7
message
interfaces
for
requests
and
responses,
namely
Psr\Http\Message\ServerRequestInterface
and
ResponseInterface.
ResponseInterface
to
short-circuit
the
pipeline
or
delegate
to
the
next
component
by
calling
$handler->handle($request).
The
final
outcome
is
a
ResponseInterface
produced
by
either
the
last
middleware
or
the
final
request
handler.
widely
supported
by
PHP
frameworks
and
libraries,
and
many
projects
offer
PSR-15
compatible
middleware
or
adapters
to
integrate
with
different
stacks.
not
define
how
requests
are
received
by
servers,
but
standardizes
how
middleware
and
handlers
interact
within
a
server-side
pipeline.