Step 2: The Server returns a Response¶
Once a server has received the request, it knows exactly which resource the client needs (via the URI) and what the client wants to do with that resource (via the method). For example, in the case of a GET request, the server prepares the resource and returns it in an HTTP response. Consider the response from the xkcd web server:nslated into HTTP, the response sent back to the browser will look something like this:
1 2 3 4 5 6 7 8 | HTTP/1.1 200 OK
Date: Sat, 02 Apr 2011 21:05:05 GMT
Server: lighttpd/1.4.19
Content-Type: text/html
<html>
<!-- ... HTML for the xkcd comic -->
</html>
|
Like the request, an HTTP response contains additional pieces of information known as HTTP headers. For example, one important HTTP response header is
Content-Type
. The body of the same resource could be returned in multiple
different formats like HTML, XML, or JSON and the Content-Type
header uses
Internet Media Types like text/html
to tell the client which format is
being returned. A list of common media types can be found on Wikipedia's
List of common media types article.Many other headers exist, some of which are very powerful. For example, certain headers can be used to create a powerful caching system.
Requests, Responses and Web Development¶
This request-response conversation is the fundamental process that drives all communication on the web. And as important and powerful as this process is, it's inescapably simple.The most important fact is this: regardless of the language you use, the type of application you build (web, mobile, JSON API), or the development philosophy you follow, the end goal of an application is always to understand each request and create and return the appropriate response.
Symfony is architected to match this reality.
To learn more about the HTTP specification, read the original HTTP 1.1 RFC
or the HTTP Bis, which is an active effort to clarify the original
specification. A great tool to check both the request and response headers
while browsing is the Live HTTP Headers extension for Firefox.
No comments:
Post a Comment