WEB API Interview Questions

Q: Content Negotiation In Web API is β€œthe process of selecting the best representation for a given response when there are multiple representations available.” The statement is True or False
Answer: True

Q: Which statement is true for Http header “Accept”
Statement 1: Accept specifies which media types are acceptable for the response such as “application/Json”, “application/xml”
Statement 2: Accept specifies which Character sets are acceptable
Answer: Statement 1

Q: Is Web API can be used with Web forms
Statement 1: Yes, Web API can be implemented in Web Forms through below steps
1. Drive a controller class from WebAPI Controller
2. Add route table to Application Start of Global.asax class.
3. Now, make http call to Web API either from Ajax/Jquery or from server side
Statement 2: No, It can’t be Implemented
Answer: Statement 1

Q: What is the correct way to create a Alias for Web API action method
Option 1:
[ActionName(“GetDataOnID”)]
Public void GetData(int ID)
{
// place your logic here
}
Option 2:
[ActionName = “GetDataOnID”]
Public void GetData(int ID)
{
// place your logic here
}
Answer: Option 1

Q: If some unhandled exception occurs in Web API which is not handled through Exception Filters, then the client will receive error message “Internal Server Error”. Is this true or not
Answer: True

Q: Exception Filters in Web API can be registered at what level
Option 1: At Controller level only
Option 2: At Action Method Level, At Controller Level and At Global Level
Answer: Option 2

Q: Can we restrict a particular Action method in WEB API to be called from Http Post verb only.
Option 1: Yes, by decorating the Action Method with [HttpPost] attribute
Option 2: No, all Action Methods are accessible for all Http Verbs
Answer: Option 1

Q: Can we configure WEB API to work over TCP protocol
Option 1: Yes, we can by changing the configuration file
Option 2: No, WEB API only works with Http protocol
Answer: Option 2

Q: Is WEB API generate proxy classes when they are called
Option 1: No, they are accessed over simple Http protocol
Option 2: Yes, proxy classes are used by clients to check what action methods are exposed by WEB API
Answer: Option 1

Good Luck, Go Crack Interviews πŸ˜‰

Advertisements

MVC Interview Questions & Answers – Part 1

Q: How I can prevent a public method in MVC controller from being an Action Method?
A: We can decorate the public method with “NonActionAttribute”. This will prevent public methods to be called as Action methods which is the default behavior of MVC.

Q: Is given below is a valid Route Definition?
{controller}{action}/{id}
A: No, its not because there is no literal value or delimiter between the placeholders. Therefore, routing cannot determine where to separate the value for the controller placeholder from the value for the action placeholder. Valid definition will be
{controller}/{action}/{id}

Q: How do you handle variable number of parameters in a route definition?
A: You can define different number of parameters in a route using “Catch-All” parameters. Example is shown below:
controller/{action}/{*parametervalues}
* is referred to as catch-all parameter which can catch all parameters.

Q: What are different scenario where Routing Mechanism will not work?
A: There are generally 2 scenario where routing will be ineffective:

 

  • If there is some physical file is there at the given url pattern like an Image, CSS or some other content file. But we can override this default behavior by setting RouteExistingFiles property of the RouteCollection object to true
  • If we explicitly disable some routes for a given url pattern. In this case url with particular patterns will be ignored. This can be done by using RouteCollection.Ignore() method.

Q: What are the different levels at which you can apply Filters?
A: Filters can be applied at 3 different levels:

 

  • On Action Method
  • On Individual Controller
  • On Entire Application

Q: What are the various types of Filters and which filter executes First and Last?
A: There are 4 different types of filters:

 

  • Authorization Filters
  • Action Filters
  • Result Filters
  • Exception Filters

Authorization Filter executes first while Exception filter executes lasts.