you have an incredibly rich way of defining caching policies for your services. We will
It doesn't end with caching, though. Consider both PUT and DELETE. Because they are
idempotent, neither the client nor the server has to worry about handling duplicate message
delivery. This saves a lot of bookkeeping and complex code.
The third architectural principle of REST is that your services should be representation-ori-
ented. Each service is addressable through a specific URI and representations are exchanged
between the client and service. With a GET operation, you are receiving a representation of
the current state of that resource. A PUT or POST passes a representation of the resource to
the server so that the underlying resource's state can change.
In a RESTful system, the complexity of the client-server interaction is within the representa-
tions being passed back and forth. These representations could be XML, JSON, YAML, or
really any format you can come up with.
With HTTP, the representation is the message body of your request or response. An HTTP
message body may be in any format the server and client want to exchange. HTTP uses the
Content-Type header to tell the client or server what data format it is receiving. The
Content-Type header value string is in the Multipurpose Internet Mail Extension (MIME)
format. The MIME format is very simple:
type / subtype ; name = value ; name = value ...
type is the main format family and subtype is a category. Optionally, the MIME type can
have a set of name/value pair properties delimited by the “;” character. Some examples are:
text / plain
text / html
application / xml
text / html ; charset = iso - 8859 - 1
One of the more interesting features of HTTP that leverages MIME types is the capability of
the client and server to negotiate the message formats being exchanged between them. While
not used very much by your browser, HTTP content negotiation is a very powerful tool when
you're writing web services. With the Accept header, a client can list its preferred response
formats. Ajax clients can ask for JSON, Java for XML, Ruby for YAML. Another thing this
is very useful for is versioning of services. The same service can be available through the
same URI with the same methods (GET, POST, etc.), and all that changes is the MIME type.
For example, the MIME type could be application/vnd+xml for an old service, while new-