title: How to autoformat API response in .NET core 5 Web API project?
body: <p>I Have an API with formatted response look's like this following JSON:</p>
  <pre><code>{
      &quot;statusCode&quot;: 200,
      &quot;totalRecord&quot;: 2,
      &quot;message&quot;: &quot;Succesfully get merchants&quot;,
      &quot;data&quot;: [
          {
              &quot;id&quot;: 1,
              &quot;name&quot;: &quot;Leo Shop&quot;,
              &quot;address&quot;: &quot;Flower Street 9A&quot;,
              &quot;isComplete&quot;: false,
              &quot;createdAt&quot;: &quot;2021-05-30T14:16:27.654233&quot;,
              &quot;updatedAt&quot;: &quot;2021-05-30T14:16:28.515476&quot;
          },
          {
              &quot;id&quot;: 3,
              &quot;name&quot;: &quot;Test Shop&quot;,
              &quot;address&quot;: &quot;Playing Street 12A&quot;,
              &quot;isComplete&quot;: false,
              &quot;createdAt&quot;: &quot;2021-05-30T14:16:27.654233&quot;,
              &quot;updatedAt&quot;: &quot;2021-05-30T14:16:28.515476&quot;
          }
      ]
  }
  </code></pre>
  <p>And code behind those response look's like this following code :</p>
  <pre><code>[HttpGet]
  public async Task&lt;ActionResult&lt;IEnumerable&lt;Merchant&gt;&gt;&gt; GetMerchants()
  {
      var data = await _context.Merchants.ToListAsync();
      ApiResponse res = new ApiResponse{StatusCode = 200, Message = &quot;Succesfully get merchants&quot;, TotalRecord = data.Count, Data = data}; // Focus on this line
      return Ok(res);
  }
  </code></pre>
  <p>My question, how to automatically convert default response As <code>ApiResponse</code> model without repeating to write <code>new ApiResponse()</code> model on every action return inside every controller?</p>
  <p>Hopefully anyone can help me.. Thanks in advance guys</p>