Java Reference
In-Depth Information
HTTP 2.0, which is mostly based on the SPDY protocol invented at
Google, further optimizes HTTP transfers through header compres‐
sion, pipelining requests and responses, and asynchronous connec‐
tion multiplexing. However, these optimizations are usually per‐
formed in a translation layer that shields application programmers
from the details, so the code you write will still mostly follow the
preceding steps 1-4. Java does not yet support HTTP 2.0; but when
the capability is added, your programs shouldn't need to change to take
advantage of it, as long as you access HTTP servers via the URL and
URLConnection classes.
HTTP Methods
Communication with an HTTP server follows a request-response pattern: one stateless
request followed by one stateless response. Each HTTP request has two or three parts:
• A start line containing the HTTP method and a path to the resource on which the
method should be executed
• A header of name-value fields that provide meta-information such as authentica‐
tion credentials and preferred formats to be used in the request
• A request body containing a representation of a resource ( POST and PUT only)
There are four main HTTP methods, four verbs if you will, that identify the operations
that can be performed:
GET
POST
PUT
DELETE
If that seems like too few, especially compared to the infinite number of object-oriented
methods you may be accustomed to designing programs around, that's because HTTP
puts most of the emphasis on the nouns: the resources identified by URIs. The uniform
interface provided by these four methods is sufficient for nearly all practical purposes.
These four methods are not arbitrary. They have specific semantics that applications
should adhere to. The GET method retrieves a representation of a resource. GET is side-
effect free, and can be repeated without concern if it fails. Furthermore, its output is
often cached, though that can be controlled with the right headers, as you'll see shortly.
In a properly architected system, GET requests can be bookmarked and prefetched
without concern. For example, one should not allow a file to be deleted merely by fol‐
Search WWH ::




Custom Search