title: How to properly post-process Refit return values?
body: <p>I'm writing some APIs using <a href="https://github.com/reactiveui/refit" rel="noreferrer">Refit</a>, which works wonders, and I'm having some trouble figuring out a good (as in "clean", "proper") way to perform some arbitrary processing on the returned data.</p>
  
  <p>As an example, consider this code:</p>
  
  <pre><code>public interface ISomeService
  {
      [Get("/someurl/{thing}.json")]
      Task&lt;Data&gt; GetThingAsync([AliasAs("thing")] string thing);
  }
  </code></pre>
  
  <p>Now, a lot of REST APIs I've seen have the unfortunate habit of packing the actual data (as in "useful" data) deep into the JSON response. Say, the actual JSON has this structure:</p>
  
  <pre><code>{
      "a" = {
          "b" = {
              "data" = {
  ...
  }
  </code></pre>
  
  <p>Now, typically I'd just map all the necessary models, which would allow Refit to correctly deserialize the response. This though makes the API a bit clunky to use, as every time I use it I have to do something like:</p>
  
  <pre class="lang-cs prettyprint-override"><code>var response = await SomeService.GetThingAsync("foo");
  var data = response.A.B.Data;
  </code></pre>
  
  <p>What I'm saying is that those two outer models are really just containers, that don't need to be exposed to the user. Or, say the <code>Data</code> property is a model that has another property that is an <code>IEnumerable</code>, I might very well just want to directly return that to the user.</p>
  
  <p>I have no idea on how to do this without having to write useless wrapper classes for each service, where each one would also have to obviously repeat all the XML comments in the interfaces etc., resulting in even more useless code floating around.</p>
  
  <p>I'd just like to have some simple, optional <code>Func&lt;T, TResult&gt;</code> equivalent that gets called on the result of a given Refit API, and does some modifications on the returned data before presenting it to the user.</p>