@@ -12,21 +12,20 @@ understanding a basic Request-Response flow in HTTP is not difficult. This
1212chapter will walk you through the HTTP fundamental basics and what this means
1313for Symfony.
1414
15- HTTP is Simple
16- --------------
15+ Requests and Responses in HTTP
16+ ------------------------------
1717
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:
2221
2322.. image :: /images/http-xkcd.png
2423 :align: center
2524
2625And 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.
3029
3130Symfony is built from the ground up around that reality. Whether you realize
3231it or not, HTTP is something you use every day. With Symfony, you'll learn
@@ -35,8 +34,8 @@ how to master it.
3534.. index ::
3635 single: HTTP; Request-response paradigm
3736
38- Step1 : The Client Sends a Request
39- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37+ Step 1 : The Client Sends a Request
38+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4039
4140Every conversation on the web starts with a *request *. The request is a text
4241message 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:
6160 This simple message communicates *everything * necessary about exactly which
6261resource the client is requesting. The first line of an HTTP request is the
6362most important, because it contains two important things: the HTTP method (GET)
64- and the URL (``/ ``).
63+ and the URI (``/ ``).
6564
6665The URI (e.g. ``/ ``, ``/contact ``, etc) is the unique address or location
6766that identifies the resource the client wants. The HTTP method (e.g. ``GET ``)
6867defines what the client wants to *do * with the resource. The HTTP methods (also
6968known as verbs) define the few common ways that the client can act upon the
7069resource - the most common HTTP methods are:
7170
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.
8179
8280With this in mind, you can imagine what an HTTP request might look like to
8381delete a specific blog entry, for example:
@@ -91,8 +89,7 @@ delete a specific blog entry, for example:
9189 There are actually nine HTTP methods defined by the HTTP specification,
9290 but many of them are not widely used or supported. In reality, many
9391 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 `_.
9693
9794In addition to the first line, an HTTP request invariably contains other
9895lines of information called request **headers **. The headers can supply a wide
@@ -130,15 +127,17 @@ like this:
130127 The HTTP response contains the requested resource (the HTML content in this
131128case), as well as other information about the response. The first line is
132129especially 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.
138137
139138Like the request, an HTTP response contains additional pieces of information
140139known 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
142141Internet Media Types like ``text/html `` to tell the client which format is
143142being returned. You can see a `List of common media types `_ from IANA.
144143
@@ -157,14 +156,11 @@ type of application you build (web, mobile, JSON API) or the development
157156philosophy you follow, the end goal of an application is **always ** to understand
158157each request and create and return the appropriate response.
159158
160- Symfony is architected to match this reality.
161-
162- .. tip ::
159+ .. seealso ::
163160
164161 To learn more about the HTTP specification, read the original `HTTP 1.1 RFC `_
165162 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.
168164
169165.. index ::
170166 single: Symfony Fundamentals; Requests and responses
0 commit comments