title: Same Web API return multiple formats
body: <p>I am working on a Asp.Net Web API project, where I need to create it in a way so that 2 different clients can consume it and get response in there desired formats.</p>
  <p>Need to provide support for both JSON and XML formats.</p>
  <p>I have tried something in Register method in WebApiConfig file:</p>
  <pre><code>public static void Register(HttpConfiguration config)  
  {  
      // Adding formatter for Json   
      config.Formatters.JsonFormatter.MediaTypeMappings.Add(  
          new QueryStringMapping(&quot;type&quot;, &quot;json&quot;, new MediaTypeHeaderValue(&quot;application/json&quot;)));  
        
      // Adding formatter for XML   
      config.Formatters.XmlFormatter.MediaTypeMappings.Add(  
          new QueryStringMapping(&quot;type&quot;, &quot;xml&quot;, new MediaTypeHeaderValue(&quot;application/xml&quot;)));  
  }  
  </code></pre>
  <p>Here client can consume API but need to pass query string type=json or xml to get response in desired format.</p>
  <pre><code>http://localhost:1312/api/Blog?type=xml
  http://localhost:1312/api/Blog?type=json 
  </code></pre>
  <p>Is there a better way to detect client's desired format and respond accordingly? If we get it from header of request or something like that, TIA.</p>