Prev | Current Page 293 | Next

Brad Ediger

"Advanced Rails"


However, this is not always optimal within the REST model.
All of these are clearly different representations of the same resource, and yet they
have different URIs. Many argue that the URI should name only the resource, and
not the representation. How would it be possible to use the same name to refer to all
of these resources?
The answer is content negotiation. This is a part of the HTTPrequest and response
where the client and server negotiate some common parameters so that they can
communicate.
As a whole, HTTPcontent negotiation is very flexible; it can negotiate a representation
based on language (through the Accept-Language request header), character
encoding (through the Accept-Charset header), content coding (Accept-Encoding), or
content type (Accept). It is the latter that we are most concerned with.
Rather than specifying the content type explicitly in the URI, we specify an Accept
header in the HTTPrequest. This header lists the content types we are willing to
What Is REST? | 195
accept, in decreasing order of priority. Under content negotiation on the preceding
service, this request would return the HTML version:
GET /orders/124 HTTP/1.1
Host: www.example.com
Accept: text/html, application/xhtml+xml, text/*, image/png, image/*, */*
Clients can vary their Accept header to request different representations of the
requested resource, and the server will try to satisfy the request with any representations
it can serve.


Pages:
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305