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

In which .NET framework the ASP .NET Web API was introduced?

The first version of ASP.NET Web API was introduced in .NET Framework 4. After that, all the later versions of the .NET Framework support the ASP.NET Web API.

Posted Date:- 2021-10-05 07:47:32

What do you understand by Internet Media Types?

The Internet Media Type is a file identification mechanism on the MIME encoding system. It is also known as the "MIME type." It has become the de facto standard for identifying content on the Internet.
For example, suppose we receive an email from a server with an attachment, then the server embeds the media type of the attachment in the message header. So, the browser can launch the appropriate helper application or plug-in.

Posted Date:- 2021-10-05 07:46:44

What do you understand by the HTTP Status Codes?

The Response Header of each API response consists of an HTTP Status Code. The HTTP Status Codes are the three-digit integers that contain the server response. Here, each number specifies a meaning. The first digit of the Status-Code defines the class of response. According to this first number, the HTTP Status Codes are categorized into five types.

Posted Date:- 2021-10-05 07:45:49

What is Web API Versioning, and why is it used?

Web API Versioning is a technique in which Web API is arranged to cope with the business changes, and the API will not impact the client that is using/consuming the existing API. As we know, multiple clients can consume the Web API at a time, so Web API versioning is necessary and required as the business grows, and business requirement changes with the time.

Posted Date:- 2021-10-05 07:44:19

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

In ASP.NET Web API, an HTTP request is used to map to the controller. The Web API framework uses a routing table to determine which action is to invoke.

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

Is it possible to pass multiple complex types in Web API?

Yes, we can easily pass multiple complex types in Web API by using the following two methods:

* Using ArrayList
* Using Newtonsoft array

Posted Date:- 2021-10-05 07:42:55

Where is the route defined in Web API?

It is placed in the App_Start directory.

App_Start –> WebApiConfig.cs


name: “myroute”,

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

defaults: new { id = RouteParameter.Optional }


Posted Date:- 2021-10-05 07:41:50

What is Parameter Binding in ASP.NET Web API?

Parameter Binding is a process that specifies that when a Web API calls a method on a controller, it must set the values for the parameters.

By Default, Web API uses the following rules to bind the parameter:

>> FromUri: If the parameter is of "Simple" type, the Web API tries to get the URI value. Simple Type includes.Net Primitive type like int, double, etc., DateTime, TimeSpan, GUID, string, any type which can convert from the string type.

>> FromBody: If the parameter is of "Complex" type, the Web API only binds the values from the message body.

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

How to enable attribute routing?

To enable attribute routing, MapHttpAttributeRoutes(); method can be called in the WebApi config file.

public static void Register(HttpConfiguration config)


// Web API routes


// Other Web API configuration not shown.


Posted Date:- 2021-10-05 07:39:36

Can we apply constraints at the route level?

Yes, it can be applied.

public User GetStudentById(int id) { … }

public User GetStudentByName(string name) { … }

You can select the first route whenever the “id” segment of the URI is an integer. Or else, you can choose the second route.

Posted Date:- 2021-10-05 07:38:57

How to enable SSL to ASP.NET web?

In order to enable SSL to ASP.NET web, you can click on project properties where you can see this option.

Posted Date:- 2021-10-05 07:38:14

Write a LINQ code for authenticating the user?

public static bool Login(string UN, string pwd)


StudentDBEntities students = new StudentDBEntities()

students.sudent.Any(e => e.UserName.Equals(UN) && e=>e.Password.Equlas(UN)) // students has more than one table


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

How can we make sure that Web API returns JSON data only?

To make Web API serialize the returning object to JSON format and returns JSON data only. For that you should add the following code in WebApiConfig.cs class in any MVC Web API Project:



Config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));






Config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"))

Posted Date:- 2021-10-05 07:36:44

Who can consume WebAPI?

WebAPI can be consumed by any client which supports HTTP verbs such as GET, PUT, DELETE, POST. As WebAPI services don’t need any configuration, they are very easy to consume by any client. Infract, even portable devices like Mobile devices can easily consume WebAPI which is certainly the biggest advantages of this technology.

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

Write a LINQ code for authenticating the user?

WCF services use the SOAP protocol while HTTP never use SOAP protocol. That’s why WebAPI services are lightweight since SOAP is not used. It also reduces the data which is transferred to resume service. Moreover, it never needs too much configuration. Therefore, the client can interact with the service by using the HTTP verbs.

Posted Date:- 2021-10-05 07:35:31

How can we register exception filter globally?

We can register exception filter globally using following code:

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

Posted Date:- 2021-10-05 07:34:48

How to unit test Web API?

Using Web API tools like Fiddler, we can perform unit testing in Web API. Fiddler is basically a free debugging proxy for any browser that can be used to compose and execute various HTTP requests to Web API and check HTTP response. It is simply used for testing restful web services. It allows one to inspect and check both incoming and outgoing data to monitor and modify requests and responses before the browser receives them. Below is given some setting that is needed to be done fiddler:

Fiddler – Compose Tab -> Enter Request Headers -> Enter Request Body and then execute.

Posted Date:- 2021-10-05 07:34:18

What is the use of DelegatingHandler?

DelegatingHandler is used to develop a custom Server-Side HTTP Message Handler in ASP.NET Web API. It is used to represent Message Handlers before routing in Web API.

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

What is CORS in Web API?

CORS (Cross-Origin Resource Sharing) is basically a mechanism that allows one to make requests from one website to another website in a browser that is normally not allowed by another policy called SOP (Same Origin Policy). It supports secure cross-origin requests and data transfers among clients or browsers and servers. Here, cross-origin request means requests coming from different origins. CORS simply resolves the same-origin restriction for JavaScript. One can enable CORS for web API using the respective web API package or OWIN middleware.

Posted Date:- 2021-10-05 07:32:47

What is content negotiation in ASP.Net Web API?

Content negotiation is basically a process of selecting the best representation from multiple representations that are available for a given response. It simply allows one to choose rather than negotiate content that one wants to get in response. It is performed at the server-side. In simple words, it chooses the best media type for matters to return a response to an incoming request.

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

Can we return View from ASP.NET Web API method?

No, we cannot return the view from the ASP.NET Web API method. ASP.NET web API develops HTTP services that provide raw data or information. ApiController in ASP.NET MVC application only renders data that is serialized and sent to the client. One can use a controller to provide normal views.

Posted Date:- 2021-10-05 07:31:23

Which .NET framework supports ASP.NET Web API?

.NET Framework 4.0 generally supports the first version of ASP.NET Web API. After that, .NET Framework 4.5 supports the latest version of web API i.e., ASP.NET Web API 2.

Posted Date:- 2021-10-05 07:30:34

What are Exception filters in ASP.NET Web API?

Exception filter is generally used to handle all unhandled exceptions that are generated in web API. It implements IExceptionFilters interface. It is the easiest and most flexible to implement. This filter is executed whenever the controller method throws any unhandled exception at any stage that is not an HttpResponseExecption exception.

Posted Date:- 2021-10-05 07:29:50

Can the HTTP request be mapped to the action method without using the HTTP attribute?

For the action method, there are two ways to map the HTTP request. The first way is using the trait on the action method. The second way is naming the method that starts with the HTTP verb. Taking as an example, to define a GET method, it can be defined as:

1 public void GetEmployee(int id)

2 {

3 StudentRepository.Get(id);

4 }

As it can start with GET, the above-mentioned method can be automatically mapped with the GET request.

Posted Date:- 2021-10-05 07:28:58

Who can consume Web API?

Web API is consumed by a client that supports HTTP verbs such as DELETE, GET, PUT, POST. They can quite easily be consumed by a client as Web API services do not need any configuration. Web API can be consumed very easily by portable devices.

Posted Date:- 2021-10-05 07:28:30

What do you understand by exception filters?

Exception filters are used to execute when exceptions are unhandled and thrown from a controller method. There may be several reasons for the exception. Exception filters implement the "IExceptionFilter" interface.

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

Which protocol is supported by Web API?

The only protocol supported by Web API is HTTP. Therefore, it can be consumed by a client that supports HTTP protocol.

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

Explain media Formatters in Web API 2

These are classes that are responsible for response data. The Web API understands the request data format as well as sends data in the format as expected by the clients.

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

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

It is not true! It is rather just another way to build non-SOAP based services like plain XML or JSON string. It comes with additional advantages such as using HTTP’s full features and reaching more clients such as mobile devices, etc.

Posted Date:- 2021-10-05 07:26:46

Explain method to handle error using HttpError in Web API?

In WEB API HttpError used to throw the error info in the response body. “CreateErrorResponse” method is can also use along with this, which is an extension method defined in “HttpRequestMessageExtension.”

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

Tell me the code snippet to show how we can return 404 errors from HttpError?

Code for returning 404 error from HttpError

string message = string.Format(“TestCustomer id = {0} not found”, customerid);

return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);

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

How can we register exception filter from the action?

We can register exception filter from action using following code


public TestCust GetMyTestCust (int custno)


//write the code


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

What are the differences between ASP.NET MVC and ASP.NET Web API?

MVC is used to create web applications that can return views as well as data; while ASP.NET Web API is used to create restful HTTP services simply, which returns only data and no view. In MVC, the request is mapped to the actions name; while the request is mapped to the actions based on HTTP verbs in Web API.

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

What is the usage of DelegatingHandler?

DelegatingHandler is used in the Web API to represent Message Handlers before routing.

Posted Date:- 2021-10-05 07:24:31

How can we restrict access to methods with specific HTTP verbs in Web API?

Attribute programming is widely used for this functionality. Web API also allows restricting access of calling methods with the help of specific HTTP verbs. It is also possible to define HTTP verbs as attribute over method.

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

How to unit test Web API?

We can perform a Unit test using Web API tools like Fiddler.

Here, are some setting to be done if you are using

Fiddler –Compose Tab -> Enter Request Headers -> Enter the Request Body and execute

Posted Date:- 2021-10-05 07:23:48

Name the tools or API for developing or testing web api?

Testing tools for web services for REST APIs include:

1. Jersey API
2. CFX
3. Axis
4. Restlet

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

What is Bearer Authentication in .Net Web API?

Bearer authentication is also known as Token-based authentication.

Posted Date:- 2021-10-05 07:22:56

What is ASP.Net identity?

ASP.Net identity is the membership management framework that Microsoft provides. It is very easily incorporated with Web API. This can help you to build a secure HTTP service.

Posted Date:- 2021-10-05 07:22:30

What is content negotiation in .Net Web API?

In ASP.Net Web API, content negotiation is done at the server-side. This helps in determining the media type formatter especially when it is about returning the response to an incoming request.

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

What is Token Based Authentication in Web API?

It is an approach to secure .Net Web API as it authenticates users by a signed token, also called a token-based approach.

Posted Date:- 2021-10-05 07:21:38

What is ASP.NET Web API routing?

Routing is the most important part of ASP.NET Web API. Routing is a way how Web API matches a URI to an action. It is basically a process that decides which action and controller should be called. The controller is basically a class that handles all HTTP requests. All public methods of controllers are basically known as action methods or just actions. Whenever a Web API framework receives any type of request, it routes that request to action.

There are basically two ways to implement routing in Web API as given below:
Convention-based routing: Web API supports convention-based routing. In this type of routing, Web API uses route templates to select which controller and action method to execute.

Attribute-based routing: Web API 2 generally supports a new type of routing known as attribute routing. As the name suggests, it uses attributes to define routes. It is the ability to add routes to the route table via attributes.

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

Write a code for passing ArrayList in Web API?

ArrayList paramList = new ArrayList();

Category c = new Category { CategoryId = 1, CategoryName =“MobilePhones”};

Product p = new Product { Productcode = 1, Name = “MotoG”, Price = 15500, CategoryID = 1 };



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

How can you pass multiple complex types in Web API?

Two methods to pass the complex types in Web API –

Using ArrayList and Newtonsoft array

Posted Date:- 2021-10-05 07:19:55

How can you restrict access methods to specific HTTP verbs in Web API?

With the help of Attributes (like HTTP verbs), It is possible to implement access restrictions in Web API.

It is possible to define HTTP verbs as an attribute to restrict access.



public void Method1(Class obj)



Posted Date:- 2021-10-05 07:19:39

How to implement Basic Authentication in ASP.Net Web API?

Basic Authentication in ASP.Net Web API can be implemented where the client sends a request with an Authorization header and word Basic. In Basic Authentication, the Authorization header contains a word Basic followed by a base 64 encoded string.

The syntax for Basic Authentication –

Authorization: Basic username: password

Posted Date:- 2021-10-05 07:19:01

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

It supports the following return types:

Other types such as string, int, etc.

Posted Date:- 2021-10-05 07:18:32

WCF is replaced by ASP.NET Web API. True/False?

WCF: It is a framework used for developing SOAP (Service Oriented Applications Protocols). It also supports various transport protocols as given above.

ASP.NET Web API: It is a framework used for developing non-SOAP-based services. It is limited to HTTP-based services.

No, it's not true that ASP.NET Web API has replaced WCF. WCF was generally developed to develop SOAP-based services. ASP.NET Web API is a new way to develop non-SOAP-based services such as XML, JSON, etc. WCF is still considered a better choice if one has their service using HTTP as the transport and they want to move to some other transport like TCP, NetTCP, MSMQ, etc. WCF also allows one-way communication or duplex communication.

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

What are new features used in ASP.NET Web API 2.0

ASP.NET Web API includes a number of new exciting features as given below:

* Attribute Routing

* CORS (Cross-Origin Resource Sharing)

* OWIN (Open Web Interface for .NET) self-hosting

* IHttpActionResult

* Web API OData

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

How to register exception filter globally?

It is possible to register exception filter globally using following code-



Posted Date:- 2021-10-05 07:16:42

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 experienced,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 .