Why to use the Web API when there is web service?

Posted by  Joseph Rossignol
 1701  View(s)
Rate this:

Explain why we use the web API when there are web services with a suitable example.

  1. Re: Why to use the Web API when there is web service?

    The ASP.NET Web API is an ideal or best platform for building Restful applications on the .NET Platform. So by using ASP.NET Web API, it is easy to build HTTP service and reach a broad range of clients, including browsers and mobile, tablets, all large and small devices.

    In the WCF services, developers have to configure binding to make it work whereas in asp.net WEB API they don't require to do this.

    Since currently most mobile devices, browsers, and tablets are the medium for accessing most of the internet and in that also people are using mobile apps most and also to provide data to apps which they are now going to use the Microsoft new technology called asp.net Web API. 

      One good thing also in Web API is that when user sends request to web application for getting response in JSON format they need to pass response headers as (contentType: 'application/JSON; charset=utf-8') and also for getting XML as response they need to pass (contentType: 'application/XML; charset=utf-8') both response and request return by a single method and if they want to do the same thing in web service then they need to create 2 different method for handling request one for sending response in JSON format and another one for getting response in XML and writing binding for those methods is a big task. 

    The Asp.net MVC resides in System.Web.MVC namespace the same like that web API resides in System.Web.Http namespace and asp.net MVC controller inherited from [Controller] and Web API controller inherited from [ApiController] and in MVC we have an action method which gets called from URL to handle request whereas in Web API we have Http verbs method to handle the request.