【发布时间】:2016-06-03 07:38:28
【问题描述】:
我正在关注位于此处的教程:https://docs.asp.net/en/latest/tutorials/first-web-api.html
我在 iis express 中运行 web api,并使用 postman 调用它,路径如下:
http://localhost:5056/api/todo
此调用命中构造函数,然后以某种方式调用
GetAll 函数从未被调用,甚至没有 HttpGet 动词。 如何调用?
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; }
}
}
【问题讨论】:
-
一些代码可能会有所帮助
-
用代码更新了问题。我不明白为什么要投反对票。我试图理解一些事情。诚实的问题。
标签: c# rest asp.net-web-api2