title: ASP.net Core RC2 Web API POST - When to use Create, CreatedAtAction, vs. CreatedAtRoute?
body: <p>What are the fundamental differences of those functions? All I know is all three result in a 201, which is appropriate for a successful POST request.</p>
  
  <p>I only follow examples I see online, but they don't really explain why they're doing what they're doing.</p>
  
  <p>We're supposed to provide a name for our GET (1 record by id):</p>
  
  <pre class="lang-cs prettyprint-override"><code>[HttpGet("{id}", Name="MyStuff")]
  public async Task&lt;IActionResult&gt; GetAsync(int id)
  {
       return new ObjectResult(new MyStuff(id));
  }
  </code></pre>
  
  <p>What is the purpose of naming this get function, besides that it's "probably" required for the POST function below:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[HttpPost]
  public async Task&lt;IActionResult&gt; PostAsync([FromBody]MyStuff myStuff)
  {
       // actual insertion code left out
  
       return CreatedAtRoute("MyStuff", new { id = myStuff.Id }, myStuff);
  }
  </code></pre>
  
  <p>I notice that <code>CreatedAtRoute</code> also has an overload that does not take in the route name.</p>
  
  <p>There is also <code>CreatedAtAction</code> that takes in similar parameters. Why does this variant exist?</p>
  
  <p>There is also <code>Created</code> which expects a URL and the object we want to return. Can I just use this variant and provide a bogus URL and return the object I want and get it done and over with?</p>
  
  <p>I'm not sure why there are so many variants just to be able to return a 201 to the client. In most cases, all I want to do is to return the "app-assigned" (most likely from a database) unique id or a version of my entity that has minimal information.</p>
  
  <p>I think that ultimately, a 201 response "should" create a location header which has the URL of the newly-created resource, which I believe all 3 and their overloads end up doing. Why should I always return a location header? My JavaScript clients, native mobile, and desktop apps never use it. If I issue an HTTP POST, for example, to create billing statements and send them out to users, what would such a location URL be? (My apologies for not digging deeper into the history of the Internet to find an answer for this.)</p>
  
  <p>Why create names for actions and routes? What's the difference between action names and route names?</p>
  
  <p>I'm confused about this, so I resorted to returning the <code>Ok()</code>, which returns 200, which is inappropriate for POST.</p>