MVC 4 - Web API - Alternate Implementation

In my previous post, I introduced the web api sample implementation. That was using default route with default naming for service methods. But in real environment, we may need to have our own names than default. Below I have given a sample class which implement web api with our own method names.


    public class AlternateController : ApiController
    {
        // WEB API is fully supporting CRUD for data model objects
        // This is alternate implementation

        // GET /api/values : This can be used to list down all items
        [HttpGet]
        public IEnumerable GetAllItems()
        {
            return new string[] { "value1", "value2" };
        }

        // GET /api/values/5 : This can be used to get details of one item by id
        [HttpGet]
        public string GetItemById(int id)
        {
            return "value";
        }

        // POST /api/values : This can be used to create new item
        [HttpPost]
        public void CreateItem(string value)
        {
        }

        // PUT /api/values/5 : This can be used to edit an item by id
        [HttpPut]
        public void UpdateItem(int id, string value)
        {
        }

        // DELETE /api/values/5 : This can be used to delete an item by id
        [HttpDelete]
        public void DeleteItemById(int id)
        {
        }
    }

Comments

Popular posts from this blog

Embedding PowerBI with ASP.NET Core 2 and Angular(2,4,5)

Handling Exit Event of Console Application in C#

Taxi - Cab services in Colombo - Sri Lanka