Formatters give your service the flexibility to respond to a client with the same data but in an arbitrary format depending on what the client has asked for. If a client asks for application/json
, your service will use the JSON formatter to respond with JSON.
As far as I know, formatters are only applied in the case where your method directly returns the object to be serialized. In your case, regardless of the media type that the client has asked for, you're returning a HttpResponseMessage
with a string containing html content.
Generally, you'll want to use formatters if you want your service to potentially serve up the same data in different formats depending on the Accept
header that the client has specified.