Choosing representation
Instead of only providing a fixed format of the content we return from our resource, HTTP allows us to use the Accept header in the request to figure out what format the client desires. This makes it possible to use the resource seamlessly in different types of applications and for different use cases. Returning XML, JSON, or an image, based on client preference, allows us to use the resource in automation and mobile phone apps, or embed it in image tags. If the client wants something we cannot provide, we return a 406 Not Acceptable error back to the client. We do this by throwing an HTTP exception object. If no Accept header is available, we chose to return XML. Note that we also must specify an HTTP header in the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access