CHAPTER 5 PERMUTATIONS PATTERN Request: GET /books/3791330942 (Hosting web)

CHAPTER 5 PERMUTATIONS PATTERN Request: GET /books/3791330942 HTTP/1.1 Accept: */ Accept-Language: en-ca Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50215; .NET CLR 1.1.4322) Connection: Keep-Alive Some browsers send the Accept type identifier */*, which essentially means, Send me whatever you ve got; I will accept it. Such a request is extremely unhelpful and makes it diffi cult to implement the separation of the resource from the representation. The solution to this problem is to define a default representation for the identifier */*. It s not an ideal solution, but a solution created from the necessity to send something. A good default is HTML because those clients that send */* are most likely HTML-based web browsers. Knowing the preferences of the client, and combining those preferences with the URL, it is possible to send a representation. The decisions are encapsulated into a component that routes the content. The component when called can contain the logic to do one of two things: send the appropriate content, or rewrite the URL that will send the appropriate content. The preferred approach is to rewrite the URL to something that will send the appropriate content. So, for example, if a web browser is interested in the document /book, the representation is /book/[document].html. If an XML-based REST client is interested in the content /book, the E B V N representation is /book/[content].xml. The URL rewrite approach is used for the following reasons: Content editors such as Microsoft FrontPage, Macromedia Dreamweaver, or Altova XMLSpy require a specific URL that can be used to edit content. Content editors are not able to edit different representations associated with a single URL. A generic URL can be bookmarked, but a redirection to a specific URL can be downloaded. URLs can be dynamically routed to any content, which makes it possible to include application versioning capabilities. The result is that the routing component will never know the details of the content sent to the client. The routing component knows only the URL of the content. The Accept header was illustrated as a way to provide a cue on how to redirect the request, but other HTTP headers can also be used. In the example HTTP headers, Accept-Language indicates the language that the content should be returned in. The routing component needs to consider both HTTP headers when rewriting the URL. The result could be HTML pages in multiple languages, XML content in a subset of languages and encodings, and so on. The routing component manages all the decisions and rewrites the URL to the appropriate representation. This frees the representation developer from having to figure out what content to send. Now that you have read about the architecture of the Permutations pattern, it should be obvious why the pattern is called what it is. The idea is that a resource is transformed into a set of representations, and the client can choose one of those representations. The remaining part of this chapter is about implementing the Permutations pattern.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Leave a Reply