经过建立“待办事项”的任务演示,咱们能够学会并掌握ASP.NET Core的相关知识。web
待办事项的功能以下:api
右键单击 Controllers 文件夹。post
选择“添加”>“新建构建项” 。测试
选择“包含读/写操做的 API 控制器”,而后选择“添加”。spa
取名“TodoController.cs”。接口
选择“添加”。get
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace Course001.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TodosController : ControllerBase
{
[HttpGet]
public IEnumerable
{
return new string[] { "value1", "value2" };
}
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
[HttpPost]
public void Post([FromBody] string value)
{
}
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
此时WebApi项目已经完成,并经过Postman能够对接口进行各类测试。io