CreatedAtAction

noun

say it: “kree-AY-tid at AK-shun” /kriˈeɪtɪd æt ˈækʃən/

An ASP.NET Core helper that answers 201 Created with the new item and a Location header pointing at it.

What is CreatedAtAction in ASP.NET Core?

CreatedAtAction — A controller helper for a POST that created something. It answers 201 Created, puts the new item in the body, and adds a Location header with the address where the item can be read.

[HttpPost]
public ActionResult<Product> Create(Product product)
{
    productDao.Add(product);
    return CreatedAtAction(nameof(GetById), new { id = product.ProductId }, product);
}

In a sentence

  • “The POST returns CreatedAtAction, so the client knows where to read the new product.”

Level: Journeyman · More ASP.NET Core terms at this level

Updated