Overview

Specific Type

[HttpGet]
public IEnumerable<Product> Get() => _repository.GetProducts()

IActionResult Type

Synchronous Action

[HttpGet("{id}")]
[ProducesResponseType(200, Type = typeof(Product))]
[ProducesResponseType(404)]
public IActionResult GetById(int id)
{
    if (!_repository.TryGetProduct(id, out var product))
        return NotFound();
    return Ok(product);
}

Asynchronous Action

[HttpPost]
[ProducesResponseType(201, Type = typeof(Product))]
[ProducesResponseType(400)]
public async Task<IActionResult> CreateAsync([FromBody] Product product)
{
    if (!ModelState.IsValid)
        return BadRequest(ModelState);

    await _repository.AddProductAsync(product);
    return CreatedAtAction(nameof(GetById), new { id = product.Id }, product);
}

ActionResult<T> Type