Web API Interview Questions and Answers Part 1

1) What is Web API?
Ans. Unlike WCF service Web API is a framework which is used to build/develop Http based services.

2) What is REST?
Ans. REST statnds for Representational state transfer. 
It is a architectural style, which defines rules for creating scalable services.
REST is works on HTTP protocol using its verbs GET, POST, PUT and DELETE.

3) Can we do unit test Web API?
Ans. Web API can be unit test by using Fiddler tool.
Following is the settings to be updated in Fiddler:
Compose Tab -> Enter Request Headers -> Enter the Request Body and execute

4) Can Web API return view in MVC?
Ans. We cannot return view from Web API.

5) How to restrict access to methods with specific HTTP verbs in Web API?
Ans. With the help of Attributes(like http verbs) one can implement access restrictions in Web API.
We can define HTTP verbs as attribute over method to restrict access.
Example : 
 [HttpPost]
 public void SampleMethod(SampleClass obj)
 {
    //logic
 }

6) What is Web API Routing?

Ans. Routing is nothing but pattern matching like in MVC. 
All routes will get registered in Route Tables. 
Example : 
Routes.MapHttpRoute(
 Name: "SampleWebAPIRoute",
 routeTemplate: “api/{controller}/{id}
 defaults: new { id = RouteParameter.Optional}
};

7) Differences between WCF and Web API?

WCF : 
1.WCF is a framework used for buil/develop service oriented applications. 
2.WCF can be consumed by clients which can understand XML. 
3.WCF supports wide range of protocols like HTTP, TCP, Named Pipes and more.
4.For each method there has to be attributes like – “WebGet” and “WebInvoke”
5.For REST service we need to use attribute “WebInvoke”.

Web API:
1. Web API is a framework used to build/develop HTTP based services.
2. Web API is an open source platform.
3. It supports only HTTP protocol.
4. Web API can be hosted in IIS or in application.
5. Unlike WCF Rest we can use full features of HTTP in Web API
6. This returns XML or JSON to client.

8. What are the advantages of using REST in Web API?
Ans. 
1. REST used to make less data transfers between client and server.
2. Web API supports HTTP protocol verbs for communication.



Subscribe

Receive Quality Tutorials Straight in your Inbox by submitting your Email below:

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker