Java Reference
In-Depth Information
lowing a link because a browser may GET all links on a page before the user asks it to.
By contrast, a well-behaved browser or web spider will not POST to a link without explicit
user action.
The PUT method uploads a representation of a resource to the server at a known URL.
It is not side-effect free, but it is idempotent . That is, it can be repeated without concern
if it fails. Putting the same document in the same place on the same server twice in a
row leaves the server in the same state as only putting it once.
The DELETE method removes a resource from a specified URL. It, too, is not side-effect
free, but is idempotent. If you aren't sure whether a delete request succeeded—for in‐
stance, because the socket disconnected after you sent the request but before you re‐
ceived a response—just send the request again. Deleting the same resource twice is not
a mistake.
The POST method is the most general method. It too uploads a representation of a re‐
source to a server at a known URL, but it does not specify what the server is to do with
the newly supplied resource. For instance, the server does not necessarily have to make
that resource available at the target URL, but may instead move it to a different URL.
Or the server might use the data to update the state of one or more completely different
resources. POST should be used for unsafe operations that should not be repeated, such
as making a purchase.
Because GET requests include all necessary information in the URL, they can be book‐
marked, linked to, spidered, and so forth. POST , PUT , and DELETE requests cannot be.
This is deliberate. GET is intended for noncommital actions, like browsing a static web
page. The other methods, especially POST , are intended for actions that commit to
something. For example, adding an item to a shopping cart should send a GET , because
this action doesn't commit; the user can still abandon the cart. However, placing the
order should send a POST because that action makes a commitment. This is why browsers
ask you if you're sure when you go back to a page that uses POST (as shown in
Figure 6-1 ). Reposting data may buy two copies of a book and charge your credit card
twice.
Figure 6-1. Repost confirmation
 
Search WWH ::




Custom Search