How to do it...

  1. First, let's add the WebApiCompatShim library to project.json:
"Microsoft.AspNetCore.MVC.WebApiCompatShim": "1.0.0"
  1. To use WebApiCompatShim, we have to change a little bit of code in ConfigureServices in order to add a service:
services.AddMVC().AddWebApiConventions();
  1. 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 ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.