InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
How to unit test Web API? |
|
Answer» Using Web API tools like Fiddler, we can perform UNIT TESTING in Web API. Fiddler is basically a free debugging proxy for any browser that can be USED to compose and execute various HTTP requests to Web API and CHECK HTTP response. It is simply used for testing restful web services. It allows one to inspect and check both incoming and outgoing data to monitor and modify requests and responses before the browser receives them. Below is given some SETTING that is needed to be done fiddler: |
|
| 2. |
Explain method to handle error using HttpError in Web API? |
|
Answer» CreateErrorResponse is an extension METHOD that can be USED in Web API controller methods to RETURN error codes and error MESSAGES. It creates an HttpError object and then wraps it inside an HTTPRESPONSEMESSAGE object. |
|
| 3. |
Web API uses which library for JSON serialization? |
|
Answer» JSON.NET LIBRARY is used by Web API for JSON SERIALIZATION. |
|
| 4. |
What is the use of DelegatingHandler? |
|
Answer» DelegatingHandler is used to DEVELOP a custom Server-Side HTTP MESSAGE Handler in ASP.NET Web API. It is used to represent Message Handlers before routing in Web API. |
|
| 5. |
What parameters can be passed in the URL of API? |
|
Answer» Context keys, DOCUMENTS keys, or anything that INITIATES API to hit the EXACT end-point are few PARAMETERS that one can pass in the URL to define the complete end-point. |
|
| 6. |
Name method that validates all controls on page? |
|
Answer» Page.Validate() |
|
| 7. |
What is CORS in Web API? |
|
Answer» CORS (Cross-Origin Resource Sharing) is basically a mechanism that allows one to MAKE requests from one website to another website in a browser that is normally not allowed by another POLICY CALLED SOP (Same Origin Policy). It SUPPORTS secure cross-origin requests and data transfers among clients or browsers and servers. Here, cross-origin request means requests coming from DIFFERENT origins. CORS simply resolves the same-origin restriction for JavaScript. One can enable CORS for web API using the respective web API package or OWIN middleware. |
|
| 8. |
Difference between HTTP GET vs HTTP Post? |
||||||||||||||||
|
Answer» HTTP (HYPERTEXT Transfer Protocol) simply manages request-response between client and server. It works as a request-response protocol between client and server.
|
|||||||||||||||||
| 9. |
What is content negotiation in ASP.Net Web API? |
|
Answer» Content negotiation is BASICALLY a process of selecting the best REPRESENTATION from multiple REPRESENTATIONS that are available for a GIVEN response. It simply allows one to choose rather than negotiate content that one wants to get in response. It is performed at the server-side. In simple words, it chooses the best media type for matters to return a response to an INCOMING request. |
|
| 10. |
Can we return View from ASP.NET Web API method? |
|
Answer» No, we cannot return the view from the ASP.NET WEB API method. ASP.NET web API DEVELOPS HTTP services that provide RAW data or information. ApiController in ASP.NET MVC application only renders data that is serialized and sent to the client. One can use a controller to provide normal VIEWS. |
|
| 11. |
What is HttpConfiguration in Web API? |
|
Answer» It is CONSIDERED as the main class that includes different properties with help of which one can override the DEFAULT BEHAVIOR of Web API.
|
|
| 12. |
Which .NET framework supports ASP.NET Web API? |
|
Answer» .NET FRAMEWORK 4.0 GENERALLY supports the first VERSION of ASP.NET WEB API. After that, .NET Framework 4.5 supports the latest version of web API i.e., ASP.NET Web API 2. |
|
| 13. |
What are Exception filters in ASP.NET Web API? |
|
Answer» Exception filter is GENERALLY used to HANDLE all unhandled exceptions that are generated in web API. It implements IExceptionFilters interface. It is the easiest and most flexible to implement. This filter is executed whenever the CONTROLLER method THROWS any unhandled exception at any stage that is not an HttpResponseExecption exception. |
|
| 14. |
HOW to secure ASP.NET Web API? |
|
Answer» Web API has become key to PROGRAMMING web-based interactions. It can be accessed by anyone who knows the URL. Therefore, they have become targets for hackers. One needs to SECURE Web API by controlling Web API and by deciding who can and who cannot have ACCESS to Web API. There are basically two ways or techniques that make our Web API more secure. |
|
| 15. |
What is ASP.NET Web API routing? |
|
Answer» Routing is the most important part of ASP.NET Web API. Routing is a way how Web API MATCHES a URI to an action. It is basically a process that decides which action and controller should be called. The controller is basically a class that HANDLES all HTTP requests. All public methods of CONTROLLERS are basically known as action methods or just actions. Whenever a Web API framework receives any type of request, it routes that request to action. There are basically TWO ways to implement routing in Web API as given below: |
|
| 16. |
What are the main return types supported in ASP. Net Web API? |
| Answer» | |
| 17. |
WCF is replaced by ASP.NET Web API. True/False? |
|
Answer» WCF: It is a framework used for DEVELOPING SOAP (Service Oriented Applications PROTOCOLS). It also supports various transport protocols as given above. |
|
| 18. |
What do you mean by Caching and What are its types? |
|
Answer» Caching is basically a technique or process of storing data somewhere or in the cache for future REQUESTS. The cache is a temporary storage area. Caching keeps all frequently or recently accessed files or data in the cache memory and accesses them from the cache itself rather than actual ADDRESS of data or files. The cache interface simply improves the storage mechanism for request/response object pairs that are being cached.
Types of Caching:
|
|
| 19. |
What is the difference between ApiController and Controller? |
|
Answer» APICONTROLLER: It is used to return data that is arranged in series and then sent to the client. public CLASS TweetsController : ApiController{ // GET: /Api/Tweets/ public List<Tweet> Get() { return Twitter.GetTweets(); }}CONTROLLER: It is used to provide normal views. public class TweetsController : Controller { // GET: /Tweets/ [HttpGet] public ACTIONRESULT Index() { return JSON(Twitter.GetTweets(), JsonRequestBehavior.AllowGet); }} |
|
| 20. |
What is the use of HttpResponseMessage? |
|
Answer» It is used to set response values such as header and status control. It simply allows us to work with HTTP PROTOCOL. It represents HTTP response messages that encapsulate DATA and status code. // GetEmployee action public HttpResponseMessage GetEmployee(INT id) { EMPLOYEE emp = EmployeeContext.Employees.Where(e => e.Id == id).FIRSTORDEFAULT(); if (emp != null) { return Request.CreateResponse<Employee>(HttpStatusCode.OK, emp); } else { return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee Not Found"); } } |
|
| 21. |
What are new features used in ASP.NET Web API 2.0 |
|
Answer» ASP.NET Web API INCLUDES a number of NEW exciting features as given below:
|
|
| 22. |
What are the advantages of using ASP.NET Web API? |
|
Answer» Some of the core advantages of using ASP.NET Web API are given below:
|
|
| 23. |
What is ASP.NET Web API? |
|
Answer» ASP stands for ACTIVE server pages. ASP.NET is an updated version of legacy ASP. It is a framework that is used for developing HTTP services to PROVIDE RESPONSES to client requests. It can be accessed in different applications on different platforms. It is provided by Microsoft open-source technology for developing and consuming HTTP-based services on top of .NET Framework. It is very easy to build HTTP services using ASP.NET WEB API. These services can be used by different clients as given below:
|
|