6
6
Symfony and HTTP Fundamentals
7
7
=============================
8
8
9
- Symfony is built using the HTTP Response-Request flow. This means that knowing
10
- HTTP fundamentals is an important part of understanding Symfony. Fortunately,
11
- understanding a basic Request-Response flow in HTTP is not difficult. This
12
- chapter will walk you through the HTTP fundamental basics and what this means
13
- for Symfony.
9
+ Symfony is modeled after the HTTP Response-Request flow. This means that
10
+ knowing HTTP fundamentals is an important part of understanding Symfony.
11
+ Fortunately, understanding a basic Request-Response flow in HTTP is not
12
+ difficult. This chapter will walk you through the HTTP fundamental basics and
13
+ what this means for Symfony.
14
14
15
15
Requests and Responses in HTTP
16
16
------------------------------
@@ -24,8 +24,7 @@ to communicate with each other. For example, when checking for the latest
24
24
25
25
And while the actual language used is a bit more formal, it's still dead-simple.
26
26
HTTP is the term used to describe this simple text-based language. The goal of
27
- your server is *always * to understand simple text requests and return simple
28
- text responses.
27
+ your server is *always * to understand text requests and return text responses.
29
28
30
29
Symfony is built from the ground up around that reality. Whether you realize
31
30
it or not, HTTP is something you use every day. With Symfony, you'll learn
@@ -69,13 +68,13 @@ known as verbs) define the few common ways that the client can act upon the
69
68
resource - the most common HTTP methods are:
70
69
71
70
**GET **
72
- Retrieve the resource from the server;
71
+ Retrieve the resource from the server (e.g. when visiting a page) ;
73
72
**POST **
74
- Create a resource on the server;
73
+ Create a resource on the server (e.g. when submitting a form) ;
75
74
**PUT **/**PATCH **
76
- Update the resource on the server;
75
+ Update the resource on the server (used by APIs) ;
77
76
**DELETE **
78
- Delete the resource from the server.
77
+ Delete the resource from the server (used by APIs) .
79
78
80
79
With this in mind, you can imagine what an HTTP request might look like to
81
80
delete a specific blog entry, for example:
@@ -132,8 +131,7 @@ case).
132
131
The status code communicates the overall outcome of the request back to the
133
132
client. Was the request successful? Was there an error? Different status codes
134
133
exist that indicate success, an error or that the client needs to do something
135
- (e.g. redirect to another page). A full list can be found on Wikipedia's
136
- `List of HTTP status codes `_ article.
134
+ (e.g. redirect to another page). Check out the `list of HTTP status codes `_.
137
135
138
136
Like the request, an HTTP response contains additional pieces of information
139
137
known as HTTP headers. The body of the same resource could be returned in multiple
@@ -354,19 +352,21 @@ other tools Symfony makes available - to create and return a ``Response``
354
352
object. In other words, the controller is where *your * code goes: it's where
355
353
you interpret the request and create a response.
356
354
357
- It's that easy! To review:
355
+ Conclusion
356
+ ----------
358
357
359
- * Each request executes the same, single file (called a "front controller");
358
+ To review what you've learned so far:
360
359
361
- * The front controller boots Symfony, and passes it request information;
362
-
363
- * The router matches the incoming URL to a specific route and returns information
364
- about the route, including the controller (i.e. function) that should be executed;
365
-
366
- * The controller (function) is executed: this is where *your * code creates and
367
- returns the appropriate ``Response `` object;
368
-
369
- * The HTTP headers and content of the ``Response `` object are sent back to the client.
360
+ #. A client sends an HTTP request;
361
+ #. Each request executes the same, single file (called a "front controller");
362
+ #. The front controller boots Symfony and passes the request information;
363
+ #. The router matches the request URI to a specific route and returns
364
+ information about the route, including the controller (usually a PHP method)
365
+ that should be executed;
366
+ #. The controller (PHP method) is executed: this is where *your * code creates
367
+ and returns the appropriate ``Response `` object;
368
+ #. Symfony turns your ``Response `` object into the text headers and content
369
+ (i.e. the HTTP response), which are sent back to the client.
370
370
371
371
Symfony provides a powerful set of tools for rapidly developing web applications
372
372
without imposing on your application. Normal users can quickly start development
@@ -379,7 +379,7 @@ sensible defaults. For more advanced users, the sky is the limit.
379
379
.. _`HTTP Bis` : http://datatracker.ietf.org/wg/httpbis/
380
380
.. _`Live HTTP Headers` : https://addons.mozilla.org/en-US/firefox/addon/live-http-headers/
381
381
.. _`List of HTTP header fields` : https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
382
- .. _`List of HTTP status codes` : https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
382
+ .. _`list of HTTP status codes` : https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
383
383
.. _`List of common media types` : https://www.iana.org/assignments/media-types/media-types.xhtml
384
384
.. _`Validator` : https://github.com/symfony/validator
385
385
.. _`Swift Mailer` : http://swiftmailer.org/
0 commit comments