title: Multiple return type from API
body: <h3>Input and API definition :</h3>
  
  <p>I'm consuming the following API, that responde either with a <code>Data</code> object of an <code>Error</code> object</p>
  
  <p>FooBar Method:  Ids is a list of string separated by commas  </p>
  
  <pre><code>GET: /FooBar/v1{?ids}
  GET: /FooBar/v1/{ids}
  </code></pre>
  
  <p>Request Header:</p>
  
  <pre><code>X-FooBar-Key:   ## My key ##
  </code></pre>
  
  <p>Response : 200</p>
  
  <pre><code>// if there is multiple IDs, response is an array of Data and Error
  [{
    "data": { }
  }, {
    "data": { }
  }, {
    "error": { }
  }]
  
  //If there is only one ID, response is the content of the data object
  {
      "code":     "",
      "date":     "",
      "status":   "",
      "message":  "",
      "link":     "",
      "type":     ""
  }
  </code></pre>
  
  <p>Response : 400/404/etc  , Return the content of an Error object</p>
  
  <pre><code>{
      "code":     "",
      "message":  ""
  }
  </code></pre>
  
  <h3>Output and Expected results:</h3>
  
  <p>I want to be able to check [1, N] IDs and with only one object return type <code>Response</code> with either Data or Error initialised the other at null...</p>
  
  <pre><code>public class Response
  {
      [JsonProperty("data")]
      public Data Data { get; set; }
  
      [JsonProperty("error")]
      public Error Error { get; set; }
  
      public string Id{  get; set; }
  } 
  public class Error
  {
      [JsonProperty("message")]
      public string Message { get; set; }
  
      [JsonProperty("code")]
      [JsonConverter(typeof(StringEnumConverter))]
      public ErrorCode Code { get; set; }
  }    
  public class Data
  {
      [JsonProperty("status")]
      [JsonConverter(typeof(StringEnumConverter))]
      public Status Status { get; set; }
  
      [JsonProperty("type")]
      public string Type { get; set; }
  
      [JsonProperty("code")]
      public string Code { get; set; }
  
      [JsonProperty("date")]
      public string Date { get; set; }
  
      [JsonProperty("message")]
      public string Message { get; set; }
  
      [JsonProperty("link")]
      public string Link { get; set; }
  }
  </code></pre>
  
  <h3>Attempt:</h3>
  
  <p>In order to simply the problem For now I work only on 1 Id at a time.<br>
  Using ServiceStack Client to consume the REST API.</p>
  
  <pre><code>public class FooBarAPI : IFooBarAPI
  {
      Dictionary&lt;string, string&gt; DefaultHeader;
      string BasePath; // https://foofoo.bar/FooBar/v1
      public FooBarAPI(Dictionary&lt;string, string&gt; defaultHeader, string basePath)
      {
          DefaultHeader = defaultHeader;
          BasePath = basePath;
      }
  
      public Response GetFooBar(string id)
      {
          JsonServiceClient client = new JsonServiceClient(BasePath);
          client.RequestFilter = httpReq =&gt; httpReq.Headers.Add("X-FooBar-Key", DefaultHeader["X-FooBar-Key"]);
  
          var response = 
                  client.GetAsync&lt;Response&gt;($"/{id}");    // Null as for one ID the result is type Data not Response
                  // client.GetAsync&lt;Data&gt;($"/{id}");     // Working If not Error  
  
          var toto = response.Result;
          toto.Id = id;
  
          return toto;
      }
  
      public Response[] GetFooBar(string[] ids)
      {   // 
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p>This question is not tagged with ServiceStack as I'm open to solution using : 
  HttpWebRequest/Response Class, 
  WebClient Class, 
  HttpClient Class, 
  RestSharp NuGet Package, 
  ServiceStack Http Utils, Or Anything that make my life easier.</p>
  
  <p>I am using ServiceStack because of <a href="https://docs.servicestack.net/csharp-client#async-example" rel="nofollow noreferrer">documentation</a> saying that I could use something like :</p>
  
  <pre><code>client.GetAsync(new Hello { Name = "World!" })
      .Success(r =&gt; r =&gt; r.Result.Print())
      .Error(ex =&gt; { throw ex; });
  </code></pre>
  
  <p>Using <code>Success</code> and <code>Error</code> to map single return type to my <code>Response</code> type. </p>