When defining methods for REST services, we can further specify the types of data a given method can process. For example, a GET method may be able to transfer plain text, XML, and JPG images. Each is represented by its own media type.
We can also make a media type more specific in terms of indicating the type of payload content a method is able to transfer. For example, in addition to stating that we want the GET method to transfer XML data, we can also limit it to transferring XML data associated with a business context, such as customer.
A media type can therefore be generic and based on a pre-defined industry media type (such as XML and JPG) or it can be further customized to represent unique types of content, such as those based on organization-specific business documents and records.
The most common forms of industry media types used with HTTP are those registered with IANA, which follow a standardized syntax that is also applied to custom media types.
For example, the following statement expresses a media type that supports XML-based customer content:
As with a GET statement, the media type statement is located in the HTTP message header. The request message issued by the service consumer can provide one or more of the media types it is able to support by using the Accept header, as shown here:
Upon returning the requested content, the response HTTP message provides a Content-Type header that confirms the media type of the content being returned to the service consumer:
Allowable media types are determined when designing a uniform contract, making the media type the third element to be naturally standardized for the collection of services using the uniform contract. You may recall that the uniform contract establishes a set of parent methods from which we can choose to have a service support a subset. Similarly, the uniform contract establishes a set of parent media types for each method. When designing a service, we can choose which of the available media types we want the service to use for a method.
The HTTP, URI, and IANA are the most common technologies and industry standards used to implement methods, resource identifiers, and media type elements of a REST uniform contract. The remainder of this Website therefore focuses almost exclusively on their usage.
It is also worth noting that alternative technologies and industry standards may also be used within a REST architecture, as long as their usage does not require the violation of REST constraints.