Interview questions for Web Api

1. What is the meaning of TestApi?

TestApi is a utility library of APIs. Using this library tester developer can create testing tools and automated tests for a .NET application using data-structure and algorithms.

This image has an empty alt attribute; its file name is istockphoto-827843530-612x612.jpg

2. Explain exception filters?

It will be executed when exceptions are unhandled and thrown from a controller method. The reason for the exception can be anything. Exception filters will implement “IExceptionFilter” interface.

3. How can we register exception filter from the action?

We can register exception filter from action using following code:
[NotImplExceptionFilter]. public TestCustomer GetMyTestCustomer(int custid)

{

//write the code

}
4. How you can return View from ASP.NET Web API method?

No, we can’t return a view from ASP.NET Web API Method. Web API creates HTTP services that render raw data. However, it’s also possible in ASP.NET MVC application.

5. How to register exception filter globally?

It is possible to register exception filter globally using following code-
GlobalConfiguration.Configuration.Filters.Add(new
MyTestCustomerStore.NotImplExceptionFilterAttribute());

6. Name the tools or API for developing or testing web api?

Testing tools for web services for REST APIs include:
1. Jersey API
2. CFX
3. Axis
4. Restlet

7. What is REST?

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

8. What is the difference between ASP.NET Web API and WCF?

Web API is a Framework to build HTTP Services that can reach a board of clients, including browsers, mobile, IoT Devices, etc. and provided an ideal platform for building RESTful applications. It is limited to HTTP based services. ASP.NET framework ships out with the .NET framework and is Open Source. WCF i.e. Windows Communication Foundation is a framework used for building Service Oriented applications (SOA) and supports multiple transport protocol like HTTP, TCP, MSMQ, etc. It supports multiple protocols like HTTP, TCP, Named Pipes, MSMQ, etc. WCF ships out with the .NET Framework. Both Web API and WCF can be self-hosted or can be hosted on the IIS Server.

9. What are the RESTful Services?

REST stands for the Representational State Transfer. This term is coined by the Roy Fielding in 2000. RESTful is an Architectural style for creating loosely couple applications over the HTTP. In order to make API to be RESTful, it has to adhere the around 6 constraints that are mentioned below:
1. Client and Server Separation: Server and Clients are clearly isolated in the RESTful services.
2. Stateless: REST Architecture is based on the HTTP Protocol and the server response can be cached by the clients, but no client context would be stored on the server.
3. Uniform Interface: Allows a limited set of operation defined using the HTTP Verbs. For eg: GET, PUT, POST, Delete etc.
4. Cacheable: RESTful architecture allows the response to be cached or not. Caching improves performance and scalability.

10. Why to choose Web API over WCF?

Web API is considered the best choice over WCF because of the following reasons:
• Web API uses all features of HTTP such as URIs, request/response headers, caching, versioning, various content formats, etc.
• One does not have to define or explain any extra config setting for different devices in Web API.
• Web API uses different text formats including XML because of which it is faster and more preferred for lightweight services.
• Web API also supports MVC features whereas WCF does not support MVC features.
• Web API provides more flexibility as compared to WCF.
• Web API uses standard security like token authentication, basic authentication, etc., to provide secure service whereas WCF uses WS-I standard to provide secure service.

11. How to unit test Web API?

We can perform a Unit test using Web API tools like Fiddler.
Here, are some setting to be done if you are using
Fiddler –Compose Tab -> Enter Request Headers -> Enter the Request Body and execute.

12. What is the difference between ASP.NET MVC application and ASP.NET Web API application?

ASP.NET MVC is used to create a web application which returns both data as well as View whereas Web API is used to create HTTP based Services which only returns data not view. In an ASP.NET MVC application, requests are mapped to Action Methods whereas in the ASP.NET Web API request is mapped to Action based on the Action Verbs.

13. When to prefer ASP.NET Web API over WCF?

It totally depends upon the requirement. Choose ASP.NET Web API is you want only HTTP based services only as Web API is a lightweight architecture and is good for the devices which have limited bandwidth. We can also create the REST services with the WCF, but that requires lots of configuration. In case, if you want a service that should support multiple transport protocol like HTTP, UDP, TCP, etc. then WCF will be a better option.

14. How can we restrict access to methods with specific HTTP verbs in Web API?

Attribute programming is widely used for this functionality. Web API also allows restricting access of calling methods with the help of specific HTTP verbs. It is also possible to define HTTP verbs as attribute over method.

15. What are the advantages of using Rest in Web API?

REST is very important and beneficial in Web API because of the following reasons:
• It allows less data transfer between client and server.
• It is easy to use and lightweight.
• It provides more flexibility.
• It also handles and controls various types of calls, returning various data formats.
• It is considered best for using it in mobile apps because it makes less data transfer between client and server.
• It uses simple HTTP calls for inter-machine communication rather than using more complex options like CORBA, COM+, SOAP, or RPC.

16. What is Web API 2.0?

It is basically an enhanced and modified feature of Web API. This new version supports various new features as given below:
• New Routing Attribute
• Secure ASP.NET Web API using OAuth 2.0
• Support for Cross-Origin requests using CORS
• IHttpActionResult return type
• Support for $expand, $select in OData Service
Because of all the new features of Web API 2.0, it is considered an optimal choice and suitable development model that makes it easier to develop RESTful services interfaces to different clients running on various platforms. It also supports configuring routes in the Web API method or controller level.

17. What is the usage of DelegatingHandler?

DelegatingHandler is used in the Web API to represent Message Handlers before routing.

leave your comment


Your email address will not be published. Required fields are marked *