.Net Core .Net MVC C# Interview Questions

WEB API INTERVIEW QUESTIONS

1. What is ASP.NET Web API?

ASP.NET Web API is a framework provided by the Microsoft with which we can easily build HTTP services that can reach a broad of clients, including browsers, mobile, IoT devices, etc. ASP.NET Web API provides an ideal platform for building RESTful applications on the .NET Framework.

2.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.

3.  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.

For example:If there are two clients java and .net client, one want the request service as HTTP protocol and the message format as XML whereas the .net client requires TCP Protocol as services and in Binary as message format.

4. 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.

5. What is an API?

An API (Application Programming Interface) is a software intermediary that enables two applications to communicate with each other. Example for API are Google Maps API, Amazon Advertising API, Twitter API, YouTube API, etc.

6.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.
  5. Code-On-Demand
  6. Layered System

7.What are the new features introduced in ASP.NET Web API 2.0?

The following features have been introduced in ASP.NET Web API 2.0:

  • Attribute Routing
  • CORS (Cross-Origin Resource Sharing)
  • OWIN (Open Web Interface for .NET) self-hosting
  • IHttpActionResult
  • Web API OData etc.

8. What is Request Verbs or HTTP Verbs?

Request Verbs : These HTTP verbs (GET, POST, PUT & DELETE) describe what should be done with the resource. For example do you want to create, read, update or delete an entity. GET, PUT, POST and DELETE http verbs are the most commonly used one’s. For the complete list of the HTTP verbs, please check http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

Request Header : When a client sends request to the server, the request contains a header and a body. The request header contains additional information such as what type of response is required. For example, do you want the response to be in XML or JSON.

Request Body : Request Body contains the data to send to the server. For example, a POST request contains the data for the new item that you want to create. The data format may be in XML or JSON.

Response Body : The Response Body contains the data sent as response from the server. For example, if the request is for a specific product, the response body includes product details either in XML or JSON format.

  • HTTP Get: Used to get or retrieve the resource or information only.
  • HTTP Post: Used to create a new resource on the collection of resources.
  • HTTP Put: Used to update the existing Response
  • HTTP Delete: Used to Delete an existing resource.

9. What is Parameter Binding in ASP.NET Web API?

When Web API calls a method on a controller, it must set the values for the parameters, this particular process is known as Parameter Binding. By Default, Web API uses the below rules in order to bind the parameter:

  • FromUri: If the parameter is of “Simple” type, then Web API tries to get the value from the URI. Simple Type includes.Net Primitive type like int, double, etc., DateTime, TimeSpan, GUID, string, any type which can be converted from the string type.
  • FromBody: If the parameter is of “Complex” type, then Web API will try to bind the values from the message body.

10.What is Media-Type Formatter in ASP.NET Web API? Media-Type formatter is an abstract class from which JsonMediaTypeFormatter (handle JSON format) and XmlMediaTypeFormatter (handle XML format) class derived from. Media-Type formatter are classes responsible for serializing the response data in the format that the client asked for.

Leave a Reply

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