Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Angular Backend Web API 11: API Controller erstellen

02.02.2023 (👁4613)


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)

        {

        }

    }

}