Why do we need a custom media type when using hypermedia links?
hypermedia, mediatypeformatter, rest
Solution
You don't have to use custom media types. In fact REST tries to discourage people from creating overly specific media types. The ideal is that media types should convey semantic information but not be specific to any particular service.
One problem with application/xml is that it has no standard definition for what a link looks like. Is it
`<Link rel="foo" href="/foo">`
or is it
`<foo href="/foo">`
or some other variant? How can your client know how to identify what links exist in a document without using "out of band" knowledge? "Out of band" knowledge is what you want to avoid because it is what causes clients to break when servers make changes and a client cannot protect itself against changes to out of band knowledge.
The other problem with `application/xml` is that it contains no semantics other than a hierarchy of elements and attributes. Semantics either have to be conveyed by a media type or a link relation. If you use `application/xml` then you have to use link relations to tell the client how to consume that document.
There can be a nice balance between conveying semantics in link relations and media types. But to be honest, the industry is trill trying to figure out exactly what that balance is and there are lots of people with different opinions on the subject.
I would suggest looking at application/hal+xml. It is the closest thing to generic XML but with link semantics defined.
Problem
I am currently designing an enterprise service that is purely resource oriented. After reading several blogs, books, etc. I believe REST with Hypermedia links is the way to go. However, one thing that all these blogs and books say is to not use application/xml as the media type when using the hypermedia links in the response. None of them say why except for a generic statement like - plain URIs with no link relation type do not communicate the semantics of URIs to clients. From what I understood, it is a recommended approach to define your own custom media type and make the client aware of how to read it. But if it is known that the clients connecting to my service will never be browsers, does it matter? Can't I just expose these links in my response with application/xml type? I was hoping someone here can elaborate more on this.