I will add another controller called ProductsController. For now, let's have a simple action method, GET, which will return some products. The products are hard-coded in the action method for now. The method will look like the following:
using Microsoft.AspNetCore.Mvc;using System.Collections.Generic;namespace DemoECommerceApp.Controllers{ [Produces("application/json")] [Route("api/[Controller]")] public class ProductsController : Controller { // GET: api/Products [HttpGet] public IEnumerable<Product> Get() { return new Product[] { new Product(1, "Oats", new decimal(3.07)), new Product(2, "Toothpaste", new decimal(10.89)), new Product(3, "Television", new decimal(500.90)) }; } }}
The [Route] attribute is provided with a well-defined template ...