@@ -12,21 +12,20 @@ understanding a basic Request-Response flow in HTTP is not difficult. This
12
12
chapter will walk you through the HTTP fundamental basics and what this means
13
13
for Symfony.
14
14
15
- HTTP is Simple
16
- --------------
15
+ Requests and Responses in HTTP
16
+ ------------------------------
17
17
18
- HTTP (Hypertext Transfer Protocol to the geeks) is a text language that allows
19
- two machines to communicate with each other. That's it! For example, when
20
- checking for the latest `xkcd `_ comic, the following (approximate) conversation
21
- takes place:
18
+ HTTP (Hypertext Transfer Protocol) is a text language that allows two machines
19
+ to communicate with each other. For example, when checking for the latest
20
+ `xkcd `_ comic, the following (approximate) conversation takes place:
22
21
23
22
.. image :: /images/http-xkcd.png
24
23
:align: center
25
24
26
25
And while the actual language used is a bit more formal, it's still dead-simple.
27
- HTTP is the term used to describe this simple text-based language. No matter
28
- how you develop on the web, the goal of your server is *always * to understand
29
- simple text requests, and return simple text responses.
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.
30
29
31
30
Symfony is built from the ground up around that reality. Whether you realize
32
31
it or not, HTTP is something you use every day. With Symfony, you'll learn
@@ -35,8 +34,8 @@ how to master it.
35
34
.. index ::
36
35
single: HTTP; Request-response paradigm
37
36
38
- Step1 : The Client Sends a Request
39
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37
+ Step 1 : The Client Sends a Request
38
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40
39
41
40
Every conversation on the web starts with a *request *. The request is a text
42
41
message created by a client (e.g. a browser, a smartphone app, etc) in a
@@ -61,23 +60,22 @@ In HTTP-speak, this HTTP request would actually look something like this:
61
60
This simple message communicates *everything * necessary about exactly which
62
61
resource the client is requesting. The first line of an HTTP request is the
63
62
most important, because it contains two important things: the HTTP method (GET)
64
- and the URL (``/ ``).
63
+ and the URI (``/ ``).
65
64
66
65
The URI (e.g. ``/ ``, ``/contact ``, etc) is the unique address or location
67
66
that identifies the resource the client wants. The HTTP method (e.g. ``GET ``)
68
67
defines what the client wants to *do * with the resource. The HTTP methods (also
69
68
known as verbs) define the few common ways that the client can act upon the
70
69
resource - the most common HTTP methods are:
71
70
72
- +----------+---------------------------------------+
73
- | *GET * | Retrieve the resource from the server |
74
- +----------+---------------------------------------+
75
- | *POST * | Create a resource on the server |
76
- +----------+---------------------------------------+
77
- | *PUT * | Update the resource on the server |
78
- +----------+---------------------------------------+
79
- | *DELETE * | Delete the resource from the server |
80
- +----------+---------------------------------------+
71
+ **GET **
72
+ Retrieve the resource from the server;
73
+ **POST **
74
+ Create a resource on the server;
75
+ **PUT **/**PATCH **
76
+ Update the resource on the server;
77
+ **DELETE **
78
+ Delete the resource from the server.
81
79
82
80
With this in mind, you can imagine what an HTTP request might look like to
83
81
delete a specific blog entry, for example:
@@ -91,8 +89,7 @@ delete a specific blog entry, for example:
91
89
There are actually nine HTTP methods defined by the HTTP specification,
92
90
but many of them are not widely used or supported. In reality, many
93
91
modern browsers only support ``POST `` and ``GET `` in HTML forms. Various
94
- others are however supported in `XMLHttpRequest `_, as well as by Symfony's
95
- :doc: `Routing component </components/routing/introduction >`.
92
+ others are however supported in `XMLHttpRequest `_.
96
93
97
94
In addition to the first line, an HTTP request invariably contains other
98
95
lines of information called request **headers **. The headers can supply a wide
@@ -130,15 +127,17 @@ like this:
130
127
The HTTP response contains the requested resource (the HTML content in this
131
128
case), as well as other information about the response. The first line is
132
129
especially important and contains the HTTP response status code (200 in this
133
- case). The status code communicates the overall outcome of the request back to the
134
- client. Was the request successful? Was there an error? Different status codes exist
135
- that indicate success, an error, or that the client needs to do something (e.g.
136
- redirect to another page). A full list can be found on Wikipedia's `List of HTTP status codes `_
137
- article.
130
+ case).
131
+
132
+ The status code communicates the overall outcome of the request back to the
133
+ client. Was the request successful? Was there an error? Different status codes
134
+ 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.
138
137
139
138
Like the request, an HTTP response contains additional pieces of information
140
139
known as HTTP headers. The body of the same resource could be returned in multiple
141
- different formats like HTML, XML, or JSON and the ``Content-Type `` header uses
140
+ different formats like HTML, XML or JSON and the ``Content-Type `` header uses
142
141
Internet Media Types like ``text/html `` to tell the client which format is
143
142
being returned. You can see a `List of common media types `_ from IANA.
144
143
@@ -157,14 +156,11 @@ type of application you build (web, mobile, JSON API) or the development
157
156
philosophy you follow, the end goal of an application is **always ** to understand
158
157
each request and create and return the appropriate response.
159
158
160
- Symfony is architected to match this reality.
161
-
162
- .. tip ::
159
+ .. seealso ::
163
160
164
161
To learn more about the HTTP specification, read the original `HTTP 1.1 RFC `_
165
162
or the `HTTP Bis `_, which is an active effort to clarify the original
166
- specification. A great tool to check both the request and response headers
167
- while browsing is the `Live HTTP Headers `_ extension for Firefox.
163
+ specification.
168
164
169
165
.. index ::
170
166
single: Symfony Fundamentals; Requests and responses
0 commit comments