Interview Questions 16 – What is the benefit of using REST in WebAPI?
REST is used to make fewer data transfers between client and server which make it an ideal for using it in mobile apps. WebAPI also supports HTTP protocol. Therefore, it reintroduces the traditional way of the HTTP verbs for communication.
Interview Questions 17 – Tell me the code snippet to show how we can return 404 errors from HttpError?
Code for returning 404 error from HttpError
string message = string.Format(“user id = {0} not found”, userid);
return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
Interview Questions 18 – What is the differences between MVC and WebAPI
MVC framework is used for developing applications which have User Interface. For that, views can be used for building a user interface.
WebAPI is used for developing HTTP services. Other apps can also be called the WebAPI methods to fetch that data.
Interview Questions 19 – What is the benefit of WebAPI over WCF?
WCF services use the SOAP protocol while HTTP never use SOAP protocol. That’s why WebAPI services are lightweight since SOAP is not used. It also reduces the data which is transferred to resume service. Moreover, it never needs too much configuration. Therefore, the client can interact with the service by using the HTTP verbs.
Interview Questions 20 – What is the usage of DelegatingHandler?
DelegatingHandler is used in the Web API to represent Message Handlers before routing.
Interview Questions 21 – How can we use Web API with ASP.NET Web Form?
WebAPI can be used with ASP.NET Web Form
It can be performed in three simple steps:
- Create a Web API Controller,
- Add a routing table to ApplicationStart method of Global.asax
- Then you need to make a jQuery AJAX Call to Web API method and get data.
Interview Questions 22 – How to you can limit Access to Web API to Specific HTTP Verb?
Attribute programming plays an important role. It is easy to restrict access to an ASP.NET Web API method to be called using a particular HTTP method.
Interview Questions 23 – How can assign alias name for ASP.NET Web API Action?
We can give alias name for Web API action same as in case of ASP.NET MVC by using “ActionName” attribute as follows:
|
[HttpPost]
[ActionName(“DeleteUser”)]
public void DeleteUserData(User user) { UserRepository.DeleteUser (user); } |
Interview Questions 24 – How can you handle errors in Web API?
Several classes are available in Web API to handle errors. They are HttpError, Exception Filters, HttpResponseException, and Registering Exception Filters.
Interview Questions 25 – What New Features comes with ASP.NET Web API 2.0?
The latest features of ASP.NET WebAPI framework v2.0 are as follows:
- Attribute Routing
- Cross-Origin Resource Sharing
- External Authentication
- Open Web Interface NET
- HttpActionResult
- Web API OData