Unter Controllers->Add new Controller -> API Controller with read/write actions oder empty
Wichtig: unten im Name Feld die Benennung
ArticlesController.cs
Dadurch wird schon ein gutes API Controller Construct erstellt
Controller nach API Controller with read/write actions
using Microsoft.AspNetCore.Mvc;
namespace webapi_codedocu.Controllers { [Route("api/[controller]")] [ApiController] public class ArticlesController : ControllerBase { // GET: api/<ArticlesController> [HttpGet] public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; }
// GET api/<ArticlesController>/5 [HttpGet("{id}")] public string Get(int id) { return "value"; }
// POST api/<ArticlesController> [HttpPost] public void Post([FromBody] string value) { }
// PUT api/<ArticlesController>/5 [HttpPut("{id}")] public void Put(int id, [FromBody] string value) { }
// DELETE api/<ArticlesController>/5 [HttpDelete("{id}")] public void Delete(int id) { } } }
|