Web API Interview Questions & Answers

  1. Question 1. What Is Web Api?

    Answer :

    Unlike WCF service Web API is a framework which is used to build/develop Http based services.

  2. Question 2. What Is Rest?

    Answer :

    1. REST stands for Representational state transfer. 
    2. It is a architectural style, which defines rules for creating scalable services.
    3. REST is works on HTTP protocol using its verbs GET, POST, PUT and DELETE.
  3. ASP.NET Interview Questions

  4. Question 3. Can We Do Unit Test Web Api?

    Answer :

    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.

  5. Question 4. Can Web Api Return View In Mvc?

    Answer :

    We cannot return view from Web API.

  6. ASP.NET Tutorial

  7. Question 5. How To Restrict Access To Methods With Specific Http Verbs In Web Api?

    Answer :

    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

     }

  8. Framework7 Interview Questions

  9. Question 6. What Is Web Api Routing?

    Answer :

    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}

    };

  10. Question 7. Differences Between Wcf And Web Api?

    Answer :

    WCF : 

    1. WCF is a framework used for build/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.
  11. Framework7 Tutorial
    HTTP Interview Questions

  12. Question 8. What Are The Advantages Of Using Rest In Web Api?

    Answer :

    1. REST used to make less data transfers between client and server.
    2. Web API supports HTTP protocol verbs for communication.
  13. Question 9. With Wcf Also You Can Implement Rest, So Why Webapi?

    Answer :

    • WCF was brought in to implement SOA, never the intention was to implement REST. 
    • Web API is built from Scratch and the only goal is to create HTTP services using REST.
  14. Windows Communication Foundation (WCF) Interview Questions

  15. Question 10. Web Api Where Is The Proxy?

    Answer :

    Web API doesn’t make it easy for consumers to generate a service client like a SOAP WSDL does. If you’re only ever going to have .NET clients it’s not a big deal because they can share the contract objects you implement, but other language clients will need to manually create their client objects if you don’t use SOAP.

  16. HTTP Tutorial

  17. Question 11. What Are The Advantages Using Webapi?

    Answer :

    • OData support (via Queryable attribute) 
    • Content Negotiation
    • Filters
    • Model binding and validation
    • Ability to self host outside of IIS
    • Link generation to related resources that incorporates routing rules
    • Full support for routes/routing
    • Ability to create custom help and test pages using ApiExplorer
  18. Java XML Interview Questions

  19. Question 12. Differentiate Between Wcf And Web Api?

    Answer :

    WCF – Windows Communication Foundation(WCF) has been created by Microsoft with .NET Framework 3.0. It supports SOAP based services. It has compatibility with HTTP, TCP, UDP, etc. Good for developing secure and interoperable services. Used for back end purposes.

    WEB API – Web API open source framework. It has compatibility with HTTP only. It has a support for non-SOAP based services. It is very light weight hence good for developing services for low bandwidth devices. It supports OData. It supports most of the MVC features. Used for front end purposes.

  20. ASP.NET Interview Questions

  21. Question 13. What Is Testapi?

    Answer :

    TestApi is a library of utility and test APIs through which testers and developers create testing tools and automated tests for .NET and Win32 application using data-structure and algorithms.

  22. Windows Communication Foundation (WCF) Tutorial

  23. Question 14. What Are Exception Filters?

    Answer :

    Exception filters will be executed when some of the exceptions are unhandled and thrown from a controller method. The reason for the exception may be anything. Exception filters will implement “Exception Filter” interface.

  24. Question 15. How Can We Register Exception Filters?

    Answer :

    Three options are available to register Exception Filters which are From Action, From Controller and Global registration.

  25. JSON (JavaScript Object Notation) Interview Questions

  26. Question 16. How Can We Register Exception Filter From Action?

    Answer :

    We can register exception filter from action using following code 

    [NotImp ExceptionFilter]

    public Test Customer Get My Test Customer(in custid)

    {

    //write the code

    }

  27. Java XML Tutorial

  28. Question 17. How Can We Register Exception Filter From Controller?

    Answer :

    We can register exception filter from controller using following code:

    [NotImp ExceptionFilter]

    public class Test CustomerController : Controller

    {

    // write the code

    }

  29. Oracle iPlanet Web Server (OiWS) Interview Questions

  30. Question 18. How Can We Register Exception Filter Globally?

    Answer :

    We can register exception filter globally using following code:

    GlobalConfiguration.Configuration.Filters.Add(new MyTestCustomerStore.NotImplExceptionFilterAttribute());

  31. Framework7 Interview Questions

  32. Question 19. How To Handle Errors In Web Api?

    Answer :

    Several classes are available in Web API to handle errors. They are HttpError, HttpResponseException, Exception Filters, Registering Exception Filters.

  33. JSON (JavaScript Object Notation) Tutorial