Web API Interview Questions and Answers

1. What is ASP.NET Web API?

Web API is an open source framework to build HTTP services for broader range of clients including browsers, tablets as well as mobile phones following REST principles. It contains many of the features of MVC e.g. controllers, filters, routing etc. It can be used to develop web services applications. We can host it within the application or on IIS.

2. What are the advantages of using ASP.NET Web API?

It is an open source technology. It uses HTTP hence easy to use and handle it. It can be hosted in IIS as well as self-host outside of IIS. It supports OData. It also has full support for routing. For developing service for low bandwidth device like mobile phones, it is very good alternative due to its being light weight. If we need non-SOAP based HTTP service then it is the best option.

3. Differentiate between WCF and Web API.

WCF - Windows Communication Foundation(WCF) has been created by Microsoft with .NET Framework 3.0. It supports SOAP based services. It has compatibility with HTTP, TCP, UDP, etc. Good for developing secure and interoperable services. Used for back end purposes.
WEB API - Web API open source framework. It has compatibility with HTTP only. It has a support for non-SOAP based services. It is very light weight hence good for developing services for low bandwidth devices. It supports OData. It supports most of the MVC features. Used for front end purposes.

4. What is SOAP?

Simple Object Access Protocol (SOAP) is a protocol created by Microsoft in 1998. Structured format data can be created using SOAP that can travel over the internet. WCF uses SOAP based services. SOAP can operate over any transfer protocol like HTTP, SMTP, TCP etc. SOAP has 3 basic characteristics i.e. extensibility, neutrality and independence. A SOAP message is an ordinary XML document containing 4 elements Envelope, Header, Body and Fault.

5. What is REST?

Representational State Transfer (REST) is an architectural style which is consisting of a coordinated set of components and defined guidelines for creating services which are scalable. It is used with HTTP protocol using its verbs GET, POST, PUT and DELETE. REST does not require much bandwidth hence it is a better alternative for use over the Internet. Whenever web services use REST architecture, they are termed as RESTful APIs. REST is mainly used in developing mobile applications, social networking websites, cloud-based platforms etc.

6. Differentiate between MVC and Web API.

MVC - MVC is used to develop web applications. MVC returns the data only in JSON format using JsonResult from action method. All requests are mapped to the respective action methods. In MVC, controllers, filters, routing etc. features exist in System.Web.Mvc. It is used to develop web applications which return both view and data.
WEB API - Web API open source framework. It has compatibility with HTTP only. It has a support for non-SOAP based services. It is very light weight hence good for developing services for low bandwidth devices. All requests are mapped to the actions based on HTTP verbs. It supports most of the MVC features like controllers, filters, routing etc. features exist in System.Web.Http. Web API returns the data in particular format like JSON,XML or any other based upon the Accept header.

7. How can we use Web API with ASP.NET Web Form?

Web can be used with ASP.NET Web Form. It can be done in three simple steps: 1. You need to create a Web API Controller, 2. You have to add a routing table to Application_Start method of Global.asax and 3. You are required to make a jQuery AJAX Call to Web API method and get data.

8. Which top 5 New Features have been included in ASP.NET Web API 2?

1.Attribute Routing,
2. CORS – Cross Origin Resource Sharing,
3. OWIN (Open Web Interface for .NET) self hosting,
4. IHttpActionResult and
5. Web API OData

9. What is TestApi?

TestApi is a library of utility and test APIs through which testers and developers create testing tools and automated tests for .NET and Win32 application using data-structure and algorithms.

10. What are Exception Filters?

Exception filters will be executed when some of the exceptions are unhandled and thrown from a controller method. The reason for the exception may be anything. Exception filters will implement "IExceptionFilter" interface.