I am following a tutorial located here: https://docs.asp.net/en/latest/tutorials/first-web-api.html
and i am running the web api in iis express and call it using postman with the following path:
http://localhost:5056/api/todo
this call hits the constructor and then somehow calls the
GetAll
function which is never called and does not even have HttpGet
verb. How is it getting called?
namespace TodoApi.Controllers
{
[Route("api/[controller]")]
public class TodoController : Controller
{
public TodoController(ITodoRepository todoItems)
{
TodoItems = todoItems;
}
public IEnumerable<TodoItem> GetAll()
{
return TodoItems.GetAll();
}
[HttpGet("{id}", Name="GetTodo")]
public IActionResult GetById(string id)
{
var item = TodoItems.Find(id);
if (item == null)
return HttpNotFound();
return new ObjectResult(item);
}
public ITodoRepository TodoItems { get; set; }
}
}