Web API interview question for freshers/Web API Interview Questions and Answers for Freshers & Experienced

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

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.

Posted Date:- 2021-10-05 07:11:59

How to handle errors in Web API?

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.

Posted Date:- 2021-10-05 07:10:54

Who can consume Web API?

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.

Posted Date:- 2021-10-05 07:10:11

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

Json.NET library is generally used by Web API for JSON serialization.

Posted Date:- 2021-10-05 07:09:03

Web API supports which protocol?

Web API generally supports only HTTP protocol.

Posted Date:- 2021-10-05 07:08:02

Explain media type formatters.

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.

Posted Date:- 2021-10-05 07:06:43

What is Web API 2.0?

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.

Posted Date:- 2021-10-05 07:05:43

Can we consume Web API 2 in C# console application?

Yes, Web API 2 can be consumed in Console Application, MVC, Angular JS, or any other application.

Posted Date:- 2021-10-05 07:04:17

Explain oData with ASP.Net Web API.

OData is the acronym for Open Data Protocol. It is a Rest-based data access protocol. OData provides a way to manipulate data by making use of CRUD operation. ASP.Net Web API supports OData V3 and V4.

To use OData in ASP.Net Web API, you would need an OData package. You have to run the below command in the Package Manager Console.

Install-Package Microsoft.AspNet.Odata

Posted Date:- 2021-10-05 07:03:37

How to consume Web API using HTTPClient?

HTTPClient is introduced in HTTPClient class for communicating with ASP.Net Web API. This HTTPClient class is used either in a console application or in an MVC application.

Posted Date:- 2021-10-05 06:39:31

How to host Web API?

There are two ways how Web API application can be hosted:

* Self Hosting
* IIS Hosting

Posted Date:- 2021-10-05 06:28:56

How can we handle errors in Web API?

To handle the exception in ASP.Net Web API, the following classes shall help:

ExceptionFilters
HttpResponseException
HttpError

Posted Date:- 2021-10-05 06:28:14

How to provide Alias name for an action method in Web API?

By adding an attribute ActionName, an Alias name can be provided:

[ActionName(“InertUserData”)]
// POST api/

public void Post([FromBody]string value)

{

}

Posted Date:- 2021-10-05 06:27:32

What is Exception handling?

Exception handling is a technique to handle runtime error in the application code. In multiple ways we can handle the error in ASP.NET Web API, some of them are listed below:

1. HttpResponseException

2. HttpError

3. Exception Filters etc.

Posted Date:- 2021-10-05 06:26:53

How Web API Routes HTTP request to the Controller ASP.NET MVC?

In ASP.NET Web API, HTTP request maps to the controller. In order to determine which action is to invoke, the Web API framework uses a routing table.

Posted Date:- 2021-10-05 06:25:52

What are the main return types supported in Web API?

Following are the main return types of Web API controller action:

Void: It is used to return empty content.
HttpResponseMessage: It is used to convert the response to an HTTP message.
IHttpActionResult: It is used to internally call ExecuteAsync to create an HttpResponseMessage.
Other types: It helps us to write the serialized return value into the response body.

Posted Date:- 2021-10-05 06:25:07

What are the main advantages of using Web API?

Following are the main advantages of using Web API:

Content Negotiation
Self-Hosting
OData
Filters
Routing
Model Bindings

Posted Date:- 2021-10-05 06:24:19

What is the use of Authorize Attribute?

Web API provided a built-in authorization filter, i.e. Authorize Attribute. This filter checks whether the user is authenticated or not. If not, the user will see 401 Unauthorized HTTP Status Code.

Posted Date:- 2021-10-05 06:22:31

Explain exception filters?

It will be executed when exceptions are unhandled and thrown from a controller method. The reason for the exception can be anything. Exception filters will implement “IExceptionFilter” interface.

Posted Date:- 2021-10-05 06:21:25

What is the meaning of TestApi?

TestApi is a utility library of APIs. Using this library tester developer can create testing tools and automated tests for a .NET application using data-structure and algorithms.

Posted Date:- 2021-10-05 06:20:55

Can you use Web API with ASP.NET Web Form?

Yes, It is possible to use Web API with ASP.Net web form. As it is bundled with ASP.NET MVC framework. However, it can be used with ASP.NET Web Form.

Posted Date:- 2021-10-05 06:19:42

What is the main difference between Web API and WCF?

WCF stands for Windows Communication Foundation. It is used for service-oriented application development supporting various transport protocols such as HTTP, TCP, MSMQ. The WCF clients must be able to understand XML. On the other hand, Web API is designed specifically for HTTP services, and due to its low-bandwidth, it supports non-SOAP services and most MVC features.

Posted Date:- 2021-10-05 06:19:13

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.

Posted Date:- 2021-10-05 06:18:00

How to you can limit Access to Web API to Specific HTTP Verb?

Attribute programming plays a important role. It is easy to restrict access to an ASP.NET Web API method to be called using a particular HTTP method.

Posted Date:- 2021-10-05 06:16:15

What is Request Verbs or HTTP Verbs?

In RESTful service, we can perform all types of CRUD (Create, Read, Update, Delete) Operation. In REST architecture, it is suggested to have a specific Request Verb or HTTP verb on the specific type of the call made to the server. Popular Request Verbs or HTTP Verbs are mentioned below:

1. HTTP Get: Used to get or retrieve the resource or information only.

2. HTTP Post: Used to create a new resource on the collection of resources.

3. HTTP Put: Used to update the existing Response

4. HTTP Delete: Used to Delete an existing resource.

Posted Date:- 2021-10-05 06:15:42

What is Web API Routing?

Routing is pattern matching like in MVC.

All routes are registered in Route Tables.

For example:

Routes.MapHttpRoute(

Name: "ExampleWebAPIRoute",

routeTemplate: “api/{controller}/{id}

defaults: new { id = RouteParameter.Optional}

Posted Date:- 2021-10-05 06:14:40

Does ASP.NET Web API replace the WCF?

No, ASP.NET Web API didn’t replace WCF Service as it is only used for creating RESTful Service i.e. non-SOAP based service.

Posted Date:- 2021-10-05 06:13:44

Can we return View from Web API?

No, Web API does not return View but they return the data. APIController is meant for returning the data. So, if you need to return a view from the controller class, then make sure to use or inherit the Controller class.

Posted Date:- 2021-10-05 06:13:17

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

Posted Date:- 2021-10-05 06:12:55

How do we limit access to methods with an HTTP verb in Web API?

An attribute has to be added as shown below:

[HttpGet]
public HttpResponseMessage Test()

{

HttpResponseMessage response = new HttpResponseMessage();

///

return response;

}

[HttpPost]
public void Save([FromBody]string value)

{

}

Posted Date:- 2021-10-05 06:11:45

Do we return Views from ASP.Net Web API?

No, it is not possible as Web API creates an HTTP-based service. It is mostly available in the MVC application.

Posted Date:- 2021-10-05 06:11:20

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.

Posted Date:- 2021-10-05 06:10:59

Can we consume ASP.NET Web API in applications created using other than .NET?

Yes, we can consume ASP.NET Web API in the applications created using another language than .NET but that application must have access/supports to the HTTP protocol.

Posted Date:- 2021-10-05 06:10:39

Who can consume WebAPI?

The clients which support HTTP verbs such as GET, PUT, DELETE, POST consume WebAPI services. As WebAPI services are very easy to consume by any client because they don’t need any configuration. Portable devices like Mobile devices, IoT can easily consume WebAPI which is certainly the biggest advantages of this technology.

Posted Date:- 2021-10-05 06:10:13

Exception filters in ASP.Net Web API

Exception filters in Web API help in implementing IExceptionFilters interface. They perform when an action throws an exception at any point.

Posted Date:- 2021-10-05 06:08:56

Can we use Web API with traditional ASP.Net Forms?

Web API can easily be used with ASP.Net Forms. You can add Web API Controller and route in Application Start method in Global.asax file.

Posted Date:- 2021-10-05 06:08:40

How to secure an ASP.Net Web API?

To secure an ASP.Net Web API, we need to control the Web API and decide who all can access the API and who cannot access it. Web API can be accessed by anyone who knows about the URL.

Posted Date:- 2021-10-05 06:07:27

What is the CORS issue in Web API?

CORS is the acronym for Cross-Origin Resource Sharing. CORS solves the same-origin restriction for JavaScript. Same-origin means a JavaScript only makes AAJAX call for web pages within the same-origin.

You have to install the CORS nuget package by using Package Manager Console to enable CORS in Web API.

Open WebAPIConfig.cs file

add config.EnableCors();

Add EnableCors attribute to the Controller class and define the origin.

[EnableCors(origins: “”, headers: “*”, methods: “*”)].

Posted Date:- 2021-10-05 06:07:08

Web API uses which of the following open-source library for JSON serialization?

Web API uses Json.NET library for JSON serialization.

Posted Date:- 2021-10-05 06:06:28

Which .NET framework supports Web API?

NET 4.0 and above version supports web API.

Posted Date:- 2021-10-05 06:02:59

Web API supports which protocol?

Web App supports HTTP protocol.

Posted Date:- 2021-10-05 06:02:45

What are Media type formatters in Web API?

The Media type formatter in Web API include:

* MediaTypeFormatter – It is the base class that helps to handle serializing and deserializing strongly-typed objects.

* BefferedMediaTypeFormatter – It signifies a helper class to allow asynchronous formatter on top of the asynchronous formatter infrastructure.

Posted Date:- 2021-10-05 06:02:28

What are the several return types in ASP.Net Web API?

The various return types in ASP.Net Web API are:

* IHttpActionResult
* HttpResponseMessage
* Void
* Other Type – string, int, or other entity types.

Posted Date:- 2021-10-05 06:01:56

What are the advantages of using ASP.Net Web API?

The advantages of using ASP.Net Web API are mentioned below:

* It completes support for routing
* Is works as HTTP using standard HTTP verbs such as GET, DELETE, POST, PUT, to name a few, for all CRUD operations
* It can be hosted in IIS as well as self-host outside of IIS
* It supports OData
* It supports validation and model binding
* The response is generated in XML or JSON format by using MediaTypeFormatter

Posted Date:- 2021-10-05 06:01:13

What are the differences between Web API and WCF REST API?

Web API is suitable for HTTP-based services, while WCF REST API is ideal for Message Queue, one-way messaging, and duplex communication. WEB API supports any media format, even XML, JSON; while, WCF supports SOAP and XML format. ASP.Net Web API is ideal for building HTTP services, while WCF is perfect for developing service-oriented applications. To run Web API, there is no configuration required, while in the case of WCF, a lot of configuration is required to run it.

Posted Date:- 2021-10-05 06:00:23

Is it right that ASP.NET Web API has replaced WCF?

It’s a not at all true that ASP.NET Web API has replaced WCF. In fact, it is another way of building non-SOAP based services, i.e., plain XML or JSON string.

Posted Date:- 2021-10-05 05:59:55

Why select Web API?

* It is used to create simple, non-SOAP-based HTTP Services
* It is also an easy method for creation with Web API. With WCF REST Services
* It is based on HTTP and easy to define, expose and consume in a REST-ful way.
* It is lightweight architecture and ideal for devices that have limited bandwidth like smartphones.

Posted Date:- 2021-10-05 05:59:13

Why is Web API required? Is it possible to use RESTful services using WCF?

Yes, we can still develop RESTful services with WCF. However, there are two main reasons that prompt users to use Web API instead of RESTful services.

<> Web API increases TDD (Test Data Driven) approach in the development of RESTful services.
<> If we want to develop RESTful services in WCF, you surely need a lot of config settings, URI templates, contracts & endpoints for developing RESTful services using web API.

Posted Date:- 2021-10-05 05:58:36

What is Web API?

WebAPI is a framework which helps you to build/develop HTTP services.

Posted Date:- 2021-10-05 05:57:56

Search
R4R Team
R4R provides Web API Freshers questions and answers (Web API Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,Web API interview question for freshers,Web API Freshers & Experienced Interview Questions and Answers,Web API Objetive choice questions and answers,Web API Multiple choice questions and answers,Web API objective, Web API questions , Web API answers,Web API MCQs questions and answers R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for Web API fresher interview questions ,Web API Experienced interview questions,Web API fresher interview questions and answers ,Web API Experienced interview questions and answers,tricky Web API queries for interview pdf,complex Web API for practice with answers,Web API for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .