Q) What is ASP.NET Web API?

A) ASP.NET web API is a framework which is used to develop HTTP services. These services can be used by many clients including browsers and mobile devices.

Q) What are the Advantages of using ASP.NET Web API?

A)ASP.NET Web API uses HTTP standards and uses HTTP standard verbs like GET, POST, PUT, DELETE, etc for CRUD operations.
Its Response can be generated in JSON or XML
It has complete support for routing
ASP.NET web API can be hosted in IIS or can be self hosted outside of IIS
It supports Model Bindings.

Q) What is Web API Routing?

A)Routing is a pattern matching according to registered route tables.

Below is the example:

defaults: new { id = RouteParameter.Optional }

Q) What is the benefit of using REST in Web API?

A)Rest is used to make data transfers with minimum data which makes it an ideal for using in low bandwidth devices like Mobile Apps.

Q) How can we handle errors in Web API?

A)In Web API we can handle errors by using several predefined classes like HttpError, Exception Filters, HttpResponseException, etc.

Q) What is the difference between MVC and WebAPI?

A) MVC Framework is used for developing applications which have User Interface where as WebAPI doesn’t have any User Interface.
In MVC we can return views but in WebAPI we can only return only data.

Q) What is the difference between Web API and WCF?

A)Web API is a framework for building non SOAP based services, whereas WCF(Windows Communication Foundation) is designed to exchange Standard SOAP-based messages.

WCF can use variety of transport protocols like HTTP, TCP, NamedPipes etc, whereas Web API uses only HTTP protocol.

Q) Did Web API replace WCF?

A)No. Even though Web API has few advantages over WCF. WCF is still a better choice in following scenarios:
To use any other protocol like TCP or Named Pipes
Message Queuing scenario using MSMQ
One way or duplex communication

Q) What is the difference between ApiController and Controller?

A)API controller returns the serialized data and doesn’t return any views. Whereas the normal controller returns both.

Q) What are the new Features introduced in ASP.NET Web API 2.0?

A)Below are the new features added in ASP.NET Web API 2.0 framework:
Attribute Routing
External Authentication
CORS(Cross-Origin Resource Sharing)
OWIN(Open Web Interface for .NET)
Web API OData, etc

Q) How to restrict access to methods with specific HTTP verbs in Web API?

A)To restrict access to methods with specific HTTP verbs we have to define HTTP verbs as attribute over method as shown in below example:

public void SaveEmployee(Employee E)

Q) How to give Alias name for action methods in Web API?

A)The attribute “ActionName” can be used to give alias name for Web API actions. Below is an example:

public void SaveEmployee(Employee E)

Q) What are Exception Filters in Web API?

A)Exception filters execute whenever controller methods throw unhandled exception. These Exception filters implement “IExceptionFilter” interface

Q) How can we pass complex types in Web API?

A)Arraylist and Newtonsoft JArray can be used to pass complex types. Below is an example:

ArrayList A1=new ArrayList();
Employee E=new Employee{EmployeeId=1, EmployeeName="Emp1"};
Salary S=new Salary{SalaryId=1,EmployeeId=1,Salary=5000};

Q) What are Authentication Filters in Web API?

A)Authentication Filters provides the authentication for the actions or methods in Controller.