Home

HttpFoundation

HttpFoundation is a PHP library that provides an object-oriented representation of HTTP messages. It is the HTTP foundation component of the Symfony framework but is distributed independently as the symfony/http-foundation package, making it usable in non-Symfony projects as well. The component is widely adopted in PHP ecosystems, including Laravel and Drupal, for handling HTTP requests and responses in a framework-agnostic way.

The two central classes are Request and Response. The Request class encapsulates data from an HTTP request,

In addition to these, HttpFoundation provides supporting classes such as UploadedFile, Cookie, HeaderBag, ParameterBag, ServerBag, and

Usage and integration: In Symfony applications, HttpFoundation underpins the HTTP kernel and routing flow, translating a

History and compatibility: The component has evolved with Symfony since the early 2010s and remains a core,

including
query
parameters,
request
body
(POST
data),
attributes
used
by
routing,
cookies,
uploaded
files,
and
server
information.
It
can
be
created
from
PHP’s
global
variables
via
Request::createFromGlobals()
or
constructed
manually
for
testing.
The
Response
class
represents
the
HTTP
response
to
be
sent
to
the
client,
including
status
code,
headers,
and
content.
It
provides
methods
to
set
headers,
cookies,
and
content,
and
a
send()
method
to
deliver
the
response
to
the
client.
Session-related
utilities
(including
a
RequestStack
for
managing
multiple
concurrent
requests).
These
components
collectively
offer
a
cohesive
API
for
reading,
validating,
and
modifying
HTTP
data.
Request
into
a
Response.
It
is
also
used
in
other
PHP
projects
as
a
standalone
tool
for
building
and
manipulating
HTTP
messages
in
a
consistent,
testable
way.
widely
used
library.
It
is
compatible
with
modern
PHP
versions
and
can
be
extended
with
bridges
to
other
standards,
such
as
PSR-7,
via
additional
packages.