Chapter 4. Producing and consuming Restlet representations
This chapter covers
In part 1 of the book, we had several opportunities to discuss representations. In chapter 1 we briefly explained that representations in REST are used to transfer resource state. We pointed to appendix A for an overview of the org.restlet.representation package and to appendix D for details on RESTful representation design, covering the definition of representation classes and the importance of hypermedia as the preferred mechanism to interact with an application in REST. Finally we manipulated basic representations in chapters 2 and 3 using the StringRepresentation class and using the converter service to return String instances directly, without needing to wrap them in a complete representation.
In this chapter we explore in detail how to create and consume real-world representations. As XML is a primary language for RESTful representations, a large part of this chapter covers its deep support in Restlet. What you learn will also be applicable to other textual formats or media types. As an illustration we use a mail representation from appendix D and expose it in various formats using Restlet extensions.