Skip to main content

Why I Use WEB API in my Project Or What is the Need of Web API

With the following points I will try to resolve the confusion between choosing the Web API and other services like web services, WCF and WCF REST.
Suppose there is one situation in which you need to display your app project data, not only in a browser, but in mobile, iPhone, tablets devices and so on for a broad reach of all clients. In other words, your project must be compatible with all these devices. 



Then what will you use?
  • Will I use a web service for this? No.
    The reason for not using: 
       - Supports only XML, if I need any other format then there will be an issue
       - Very complicated to use
       - Will take lots of RAM
       - Uses complicated SOAP
       - I don't need SOAP since SOAP will only support a post request, in my project I also need a get request
       - I can host it only on IIS 


  • Will I use WCF for this? No.

      Reason
     for not using: 
       - Very complicated configuration
       - Uses complicated SOAP
       - I don't need SOAP

  • Will I use WCF REST for this ? No.

      Reason
     for not using: 
       - Supports only JSON, XML and atom formats (atom is use for web feeds).
       - This may work for my requirements, but it is also very complicated since I need to do lots of configuration in my project and on IIS also.

  • Will I use Web API?Yes, I will use the Web API.

      Reason
     for using the Web API: 
       - Supports JSON, plain XML or any format that HTTP supports using content negotiation and media type formatter
       - It is very simple to use
       - No need to describe your data, if you want you can provide PDF format
       - Supports HTTP full functionality
       - It also supports MVC features such as applying filters before or after executing an action just like MVC can
       - Due to the HTTP service it can be broadly reached by all clients.
  • The Web API is created with HTTP functionality in mind, since using this HTTP protocol, anything is broadly accessible (anything means like any image or any HTML static page and so on).
  • Now a days, users are not limited to browsers only, they want to use their app in mobile, Android, tablets and so on. So the Web API is a good fit for this.
  • The Web API automatically gains all the power of HTTP.
  • Gaining all the power of HTTP means, gaining its caching, gaining its all action method like, get, post, put and delete and so on.
  • The Web API structure is similar to MVC, so if my project is in MVC then it will be a good choice for me to create a HTTP service in the Web API.


  • The preceding figure explains that let's say, my project is in MVC and it uses the Web API that has the power of HTTP and due to that power it can easily communicate with different browsers, iPhone, Android, Laptop and so on.

Comments

Popular posts from this blog

Top 10 ASP.NET Web API Interview Questions

What is ASP.NET Web API? ASP.NET Web API is a framework that simplifies building HTTP services for broader range of clients (including browsers as well as mobile devices) on top of .NET Framework. Using ASP.NET Web API, we can create non-SOAP based services like plain XML or JSON strings, etc. with many other advantages including: Create resource-oriented services using the full features of HTTP Exposing services to a variety of clients easily like browsers or mobile devices, etc. What are the Advantages of Using ASP.NET Web API? Using ASP.NET Web API has a number of advantages, but core of the advantages are: It works the HTTP way using standard HTTP verbs like  GET ,  POST ,  PUT ,  DELETE , etc. for all CRUD operations Complete support for routing Response generated in JSON or XML format using  MediaTypeFormatter It has the ability to be hosted in IIS as well as self-host outside of IIS Supports Model binding and Validation Support for OD...

Extension methods in C#

Consider the class C# 1 2 3 4 5 6 7 8 9 10 11 12 13          namespace ExtensionMethod      {          public class testClass {              public string sayHello ( ) {              return "Hello" ;            }        }      }     Invoke the above from your form using C# 1 2 3 4 5 6          testClass test = new testClass ( ) ;      MessageBox . Show ( test . sayHello ( ) ) ;     This will show “Hello” in message box. Consider the scenario where you don...

What is cookie? Advantages and disadvantages of cookies?

What is cookie? A cookie is a small piece of text file stored on user's computer in the form of name-value pair. Cookies are used by websites to keep track of visitors e.g. to keep user information like username etc. If any web application using cookies, Server send cookies and client browser will store it. The browser then returns the cookie to the server at the next time the page is requested. The most common example of using a cookie is to store User information, User preferences, Password Remember Option etc.It is also one of the common and mostly asked interview questions. Some facts about Cookie Here are a few facts to know about cookies: · Cookies are domain specific i.e. a domain cannot read or write to a cookie created by another domain. This is done by the browser for security purpose. · Cookies are browser specific. Each browser stores the cookies in a different location. The cookies are browser specific and so a cookie created in one browser(e.g in Google Chrome...