title: HTTP Status Codes - 404/NotFound vs 204/NoContent vs 200/Ok
body: <p>I have Widget entities that belong to Company entities. There is a one-to-many relationship between Companies and Widgets.</p>
  
  <p>Here's my first pass at the Get method:</p>
  
  <pre><code>[Route("MyApi/Companies/{companyId}/WidgetAdministration/[controller]")]
  [HttpGet]
  public async Task&lt;ActionResult&lt;List&lt;WidgetDTO&gt;&gt;&gt; GetWidgets([FromRoute] int companyId)
  {
      // get company
      var company = await _xyvidContext.Companies
          .Where(c =&gt; c.CompanyId == companyId)
          .AsNoTracking()
          .Include(c =&gt; c.Widgets)
          .FirstOrDefaultAsync();
  
      if (company == null)
      {
          return NotFound();
      }
  
      // get corresponding Widgets
      List&lt;WidgetDTO&gt; widgetDtos = company.Widgets
          .AsQueryable()
          .ProjectTo&lt;WidgetDTO&gt;(_mapper.ConfigurationProvider)
          .ToList();
  
      if (widgetDtos == null)
      {
          return StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError);
      }
      else if (widgetDtos.Count == 0)
      {
          return NoContent();
      }
      else
      {
          return Ok(widgetDtos);
      }
  }
  </code></pre>
  
  <p>It is obvious that if the Company is Not Found, whether it was soft-deleted or never existed, I should return a 404/NotFound, Correct ?</p>
  
  <p>If I request to see all Widgets belonging to Company 1, but Company 1 has not Widgets, what should I return?</p>
  
  <p><strong>404/NotFound</strong> - No Widgets were found.</p>
  
  <p><strong>204/NoContent</strong> - No Widgets were found, so there is No Content to return</p>
  
  <p><strong>200/Ok with Empty Array</strong> - No Errors occurred, but what we found was an empty array, so just return that.</p>