MVC 4 - Web API

Web API is latest framework added in asp.net technologies. It further improves the MVC capabilities by introducing easy going web service concept into MVC. Same way that we create controller for handling request for pages, we can create special controller class which will work as web service which will serve the request without rendering pages. So data will be json serialized before sending to client side. In this implementation model we can create web services in seconds which more suites the MCV pattern.

Below is the simple implementation of web api.


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

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

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

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

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

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

This is worth to have a shot....

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