Difference between revisions of "Web API"

From Logic Wiki
Jump to: navigation, search
m
 
m (1 revision imported)
 
(No difference)

Latest revision as of 14:28, 9 May 2016


Web API can serve both XML and JSON with the same code. It changes response type according to HTTP Accept Type in requester header.

Building REST Services in .NET

  1. WCF
  2. MVC
  3. Web API
  • Web API require .NET 4.0 or above
  • Requires VS 2010 or Above (if vs 2010 is used manualy install ASP.NET MVC 4.0)

Starting

  • Start a new ASP.NET MVC Project
  • Choose Web API

in App_Start > WebApiConfig.cs we see default route.

in Controllers > ValuesController.cs We see functions

NuGET - > Microsoft WEB API

First API Controller

in Controllers Folder Add new Controller and choose "Empty API Controller" and name it.

public object  GET()
{
 var repo =  new CountingKsRepository(
   new CountingKsContext());
 var results = repo.GetAllFoods()
                    .OrderBy(f => f.Description)
                    .Take(25)
                    .ToList();
 return results;
}