- First, let's add the WebApiCompatShim library to project.json:
"Microsoft.AspNetCore.MVC.WebApiCompatShim": "1.0.0"
- To use WebApiCompatShim, we have to change a little bit of code in ConfigureServices in order to add a service:
services.AddMVC().AddWebApiConventions();
- Next, we will change the existing code for api/productapi/{id}:
[HttpGet("{id:int}")]public IActionResult Get(int id){ var productFromRepo = _productRepository.Find(id); if (productFromRepo == null) return NotFound(); return Ok(productFromRepo);}
We can add one more Get() method with different parameters, as follows:
[Route("{id:int}")]public HttpResponseMessage Get(int id, HttpRequestMessage request){ var product = _productRepository.Find(id); if (product ...