Explore topic-wise InterviewSolutions in .

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.

What is MVC? Write difference between MVC and Web API?

Answer»

MVC (Model, View, and Controller) is basically an application design model that comprises three interconnect parts I.e., model, view, and controller. It allows coders to factor out different components of the application and UPDATE them more easily. It is mostly used for developing model user interfaces. Its main purpose is to display PATTERNS in structure for keeping display and data separate to enable both of them to change WITHOUT affecting others. 

MVCWEB API
It can be used to build Web applications that reply as both data and views.It is used to build HTTP services that reply only as data.
It returns data in JSON format by using JSONResult.It returns data in different formats such as JSON, XML, etc.
It supports content negotiation, self-hosting.It does not support content negotiation, self-hosting.
It is not able to build REST-full services.It is very helpful in CREATING REST-full services.
It returns a view (HTML).It returns REST responses.
2.

How to register an exception filter globally?

Answer»

One can REGISTER exception FILTER globally USING FOLLOWING code:
GlobalConfiguration.Configuration.Filters.Add (new MyTestCustomerStore.NotImplExceptionFilterAttribute());
 

3.

How to handle errors in Web API?

Answer»

Web API generally provides greater FLEXIBILITY in terms of handling errors. Exception handling is a technique that is used to handle run-time errors in APPLICATION code. One can use HttpResponseException, HttpError, Exception FILTERS, register exception filters, Exception handlers to handle errors. Exception filter can be used to identify unhandled exceptions on actions or controllers, exception handlers can be used to identify any type of unhandled exception application-wide, and HttpResponseException can be used when there is the POSSIBILITY of an exception. 

4.

Who can consume Web API?

Answer»

A large range of clients such as browsers, mobile devices, iPhone, etc., include or CONSUME WEB API. It is also good for using along native applications that require web services but not SOAP support. It can also be consumed by any CLIENT that supports HTTP verbs such as GET, DELETE, POST, PUT.

5.

What are Web API filters?

Answer»

Filters are BASICALLY used to add extra logic at different LEVELS of Web API framework request processing.  Different types of Web API filters are available as given below:

  • Authentication Filter: It handles authentication and authenticates HTTP requests. It also helps to authenticate user detail. It checks the IDENTITY of the user.
  • Authorization Filter: It handles authorization. It runs before controller action. This filter is used to check whether or not a user is authenticated. If the user is not authenticated, then it returns an HTTP status code 401 without invoking the action.
  • AuthorizeAttribute is a built-in authorization filter provided by Web API.
  • Action Filter: It is attributing that one can apply to controller action or entire controller. It is used to add extra logic before or after controller action executes. It is simply a way to add extra functionality to Web API services.
  • Exception Filter: It is used to handle exceptions that are unhandled in Web API. It is used whenever controller actions throw an unhandled exception that is not HttpResponseException. It will implement an “IExceptionFilter” interface.
  • Override Filter: It is used to exclude SPECIFIC action methods or CONTROLLERS from the global filter or controller level filter. It is simply used to modify the behavior of other filters for individual action methods. 
6.

What is XML and JSON?

Answer»

XML (Extensible Markup Language): 

  • It is especially designed to store and transport data.
  • It is similar to HTML but is more flexible than HTML because it allows users to create their own custom tags.
  • It is used for representing structured INFORMATION such as documents, data, configuration, etc.


JSON (JavaScript Object Notation): 

  • It is a LIGHTWEIGHT format designed to store and transport data.
  • It is easier to understand and is a standard text-based format used for representing structured data based on JavaScript object syntax.
  • It is faster and easier to USE
7.

Which of the following Open-source libraries is used by WEB API for JSON serialization?

Answer»

Json.NET LIBRARY is generally USED by Web API for JSON serialization. 

8.

Web API supports which protocol?

Answer»

WEB API generally supports only HTTP PROTOCOL

9.

Explain media type formatters.

Answer»

In WEB API, MEDIA type formatters are classes that are responsible for serialization data. Here, serialization generally means a process of translating data into a format that can be transmitted and RECONSTRUCTED later.  Because of serializing request/response data, Web API can understand request data format in a better way and send data in a format that the client expects. It simply specifies data that is being transferred among client and SERVER in HTTP response or request. 

Media Type Formatter ClassMIME TypeDescription
JsonMediaTypeFormatterapplication/json, text/jsonHandles JSON format
XmlMediaTypeFormatterapplication/xml, text/jsonHandles XML format
FormUrlEncodedMediaTypeFormatterapplication/x-www-form-urlencodedHandles HTM form URL-encoded data
JQueryMvcFormUrlEncodedFormatterapplication/x-www-form-urlencodedHandles model-bound HTML form URL-encoded data
10.

What is Web API 2.0?

Answer»

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.

11.

What is REST and SOAP? What is different between them?

Answer»

REST (Representational State Transfer):  It is a NEW and improved form of web service. It describes the architectural style of networked systems. It does not require greater bandwidth when requests are sent to the SERVER. It just includes JSON message. For example:

{"city":"Mumbai","state":"Maharashtra"}

SOAP (Simple Object Access Protocol): It is a simple and lightweight protocol that is generally used for exchanging structured and typed information on the Web. It works mostly with HTTP and RPC (Remote Procedure Call). This protocol is mainly used for B2B applications one can define a data contract with it. SOAP messages are heavier in content and THEREFORE use greater bandwidth.

For example:

<?xml version="1.0"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope" SOAP-ENV:encodingStyle=" http://www.w3.org/2001/12/soap-encoding"><soap:Body><Demo.guru99WebService xmlns="http://tempuri.org/"> <EmployeeID>int</EmployeeID> </Demo.guru99WebService> </soap:Body></SOAP-ENV:Envelope>
RESTSOAP
It is basically an architectural pattern.It is basically a messaging protocol.
It usually works with various text formats such as PLAIN text, HTML, JSON, XML, etc.It only works with XML formats.
It is totally stateless.It has some specifications for both stateless and stateful implementation.
Its performance is faster as compared to SOAP.Its performance is slower as compared to REST.
It uses XML and JSON to send and receive data.It uses WSDL (Web Service Description Language) for communication among consumers or users and providers.
REST has to resend transfer whenever it determines any errors.SOAP includes built-in error handling for communications errors using WS-ReliableMessaging specification.
It CALLS services using the URL path.It calls services by calling RPC (Remote Procedure Call) method.
12.

What are the advantages of using Rest in Web API?

Answer»

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

What is different between REST API and RESTful API?

Answer»

REST (Representation State Transfer) API:  It is basically an architectural style that makes PRODUCTIVE USE of existing technology and protocols of the web. It is a SET of rules that developers need to follow when they develop their API or services that are scalable. It is used with HTTP protocol using its verbs such as GET, DELETE, POST, PUT. 
RESTful API: It is simply referred to as web services executing such as architecture.  

REST APIRESTful API
REST is an architectural pattern used for creating web services.RESTful API is used to implement that pattern.
The data format of REST is based on HTTP.The data format of RESTful is based on JSON, HTTP, and Text.
Working of URL is based on request and response.Working of RESTful is based on REST applications.
It is more user-friendly and highly adaptable to all business enterprises and IT.It is too flexible.
It is required to develop APIs that allow interaction among CLIENTS and servers.It simply follows REST infrastructure that PROVIDES interoperability among different systems on the whole network.
14.

Why to choose Web API over WCF?

Answer»

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

What is the difference between Web API and WCF?

Answer»

WCF (Windows Communication Foundation): It is a framework used for developing SOAP (Service-oriented applications). This framework is used for developing, configuring, and deploying, or implementing network-distributed services. 

Web API: It is an application programming interface for both web browsers and web servers. Browser API simply extends or increases the FUNCTIONALITY of web browsers whereas Server API simply extends or increases the functionality of web server.

Web APIWCF
It is used to develop both SOAP-based services and RESTful services.It is used to deploy only SOAP-based services.
It SUPPORTS various MVC features such as routing, MODEL binding, etc.It does not support any MVC features.
It only supports HTTP protocol.It supports various protocols such as HTTP, UDP, custom transport.
It is considered best for developing RESTFUL services.It supports only limited RESTFUL services.
It is good when one wants to expose an EXPENSIVE range of clients such as iPhones, browsers, mobile phones, tablets, etc.It is good for creating services that uses expedite transport channels such as TCP, UDP, Named pipes, etc.
It offers support for UTF-8 encoding format.It offers TEXT, Binary encoding support, MTOM (Message Transmission Optimization MECHANISM), etc.
16.

What are the main return types supported in Web API?

Answer»

It does not have any specific data type. It can return data of any type DEPENDING upon the business requirement. There are many HTTP methods LIKE GET, POST, PUT, etc., which can return data in different formats depending upon the use CASE

17.

What is Web API and why we use it ?

Answer»

Web API (Application Programming Interface), as the name suggests, is an API that can be accessed over the Web using the HTTP PROTOCOL. It is basically considered the best platform for revealing or uncovering data and services to various different services. It is a tool that can be USED to PUSH data to a server and can be accessed by server code. It can be built or developed using various technologies LIKE java, ASP.NET, etc. 


Web API Uses:

  • It contains additional layers that simply standardize communications and provide different options on how to format input and output.
  • It can be used with ASP.NET MVC and different types of web applications such as ASP.NET WebForms.
  • If one wants to create resource-oriented services, then Web API services are considered the best.
  • It also helps to develop REST-ful services and SOAP-based services.
18.

Why is the Web API important?

Answer»

Web API is generally considered as a service that basically provides us information or data from the server. It is very important because of the following reasons:

  • It is used to PROVIDE an interface for websites and client applications to have access to data.
  • It can also be used to access data from the database and save data BACK to the database.
  • It supports different text formats such as XML, JSON, etc.
  • It is suitable or compatible with any type of BROWSER and any type of device like mobile, desktop, web, etc.
  • It uses low bandwidth such as XML or JSON data, etc., and is therefore considered good for devices that have limited bandwidth such as smartphones, etc.
  • From a business point of view, web API is more applicable for UI/UX, increases INTEREST in the COMPANY’s product and services, increases website traffic.