ASP.Net Web API Interview Questions

    1 Votes

Top ASP.Net Web API Interview Questions and Answers for freshers and 2-5 year experienced dot net developers with explanation and examples.

1) What is Web API?

It is a framework which helps us to build/develop HTTP services. So there will a client server communication using HTTP protocol.

2) What is Representational state transfer or REST?

REST is architectural style, which has defined guidelines for creating services which are scalable. REST used with HTTP protocol using its verbs GET, POST, PUT and DELETE.

3) Explain Web API Routing?

Routing is the mechanism of pattern matching as we have in MVC. These routes will get registered in Route Tables. Below is the sample route in Web API –

Routes.MapHttpRoute(
Name: "MyFirstWebAPIRoute",
routeTemplate: “api/{controller}/{id}
defaults: new { id = RouteParameter.Optional}
};

4) List out the differences between WCF and Web API?

WCF

  • It is framework build for building or developing service oriented applications. 
  • WCF can be consumed by clients which can understand XML. 
  • WCF supports protocols like – HTTP, TCP, Named Pipes etc.

Web API

  • It is a framework which helps us to build/develop HTTP services
  • Web API is an open source platform.
  • It supports most of the MVC features which keep Web API over WCF.

5) What are the advantages of using REST in Web API?

REST always used to make less data transfers between client and server which makes REST an ideal for using it in mobile apps. Web API supports HTTP protocol thereby it reintroduces the old way of HTTP verbs for communication.

6) Difference between WCF Rest and Web API?

WCF Rest

  • WebHttpBinding” to be enabled for WCF Rest.
  • For each method there has to be attributes like – “WebGet” and “WebInvoke
  • For GET and POST verbs respectively.

Web API

  • Unlike WCF Rest we can use full features of HTTP in Web API.
  • Web API can be hosted in IIS or in application.

7) List out differences between MVC and Web API?

Below are some of the differences between MVC and Web API 

MVC

  • MVC is used to create a web app, in which we can build web pages.
  • For JSON it will return JSONResult from action method.
  • All requests are mapped to the respective action methods.

Web API

  • This is used to create a service using HTTP verbs.
  • This returns XML or JSON to client.
  • All requests are mapped to actions using HTTP verbs.

8) What are the advantages of Web API?

Below are the list of support given by Web API –

  • OData
  • Filters
  • Content Negotiation
  • Self Hosting
  • Routing
  • Model Bindings

9) Can we unit test Web API?

Yes we can unit test Web API.

10) How to unit test Web API?

We can unit test the Web API using Fiddler tool. Below are the settings to be done in Fiddler –

Compose Tab -> Enter Request Headers -> Enter the Request Body and execute

11) Can we return view from Web API?

No. We cannot return view from Web API.

12) How we can restrict access to methods with specific HTTP verbs in Web API?

Attribute programming is used for this functionality. Web API will support to restrict access of calling methods with specific HTTP verbs. We can define HTTP verbs as attribute over method as shown below

[HttpPost]
public void UpdateTestCustomer(Customer c)
{
TestCustomerRepository.AddCustomer(c);
}

13) Can we use Web API with ASP.NET Web Forms?

Yes. We can use Web API with ASP.NET Webforms.

14) List out the steps to be made for Web API to work in Web Forms?

Below are the steps to be followed –

  • Creating new controller for Web API.
  • Adding routing table to “Application_Start” method in Global.asax
  • Make a AJAX call to Web API actions.

15) Explain how to give alias name for action methods in Web API?

Using attribute “ActionName” we can give alias name for Web API actions. Eg:

[HttpPost]
[ActionName("AliasTestAction")]
public void UpdateTestCustomer(Customer c)
{
TestCustomerRepository.AddCustomer(c);
}
Page 1 of 4

Popular Videos

How to speak to people

How to speak so that people want to listen.

Got a tip or Question?
Let us know

Related Articles

C# Interview Questions
.Net Framework Interview Questions and Answers
ADO.Net Interview Questions and Answers for Freshers, Experienced
ASP.Net Interview Questions and Answers
ASP.Net MVC Interview questions and Answers
WCF Interview Questions and Answers