Click here to Skip to main content
15,881,715 members
Articles / Web Development / ASP.NET

Top 10 ASP.NET Web API Interview Questions

Rate me:
Please Sign up or sign in to vote.
4.91/5 (26 votes)
5 May 2014CPOL5 min read 543.5K   50   9
Top 10 interview questions related to ASP.NET Web API framework
In this ASP.NET Interview Questions Series, so far we have covered questions related to the core of ASP.NET technology. In this part-6 of ASP.NET Tutorial series, we will cover top 10 interview questions related to ASP.NET Web API framework.

What we have covered so far can be summarized as follows:

So, let's dive deeper to understand ASP.NET Web API technology concepts through Interview Questions.

What is ASP.NET Web API?

ASP.NET Web API is a framework that simplifies building HTTP services for broader range of clients (including browsers as well as mobile devices) on top of .NET Framework.

Using ASP.NET Web API, we can create non-SOAP based services like plain XML or JSON strings, etc. with many other advantages including:

  • Create resource-oriented services using the full features of HTTP
  • Exposing services to a variety of clients easily like browsers or mobile devices, etc.

What are the Advantages of Using ASP.NET Web API?

Using ASP.NET Web API has a number of advantages, but core of the advantages are:

  • It works the HTTP way using standard HTTP verbs like GET, POST, PUT, DELETE, etc. for all CRUD operations
  • Complete support for routing
  • Response generated in JSON or XML format using MediaTypeFormatter
  • It has the ability to be hosted in IIS as well as self-host outside of IIS
  • Supports Model binding and Validation
  • Support for OData
  • and more....

For implementation on performing all CRUD operations using ASP.NET Web API, click here.

What New Features are Introduced in ASP.NET Web API 2.0?

More new features introduced in ASP.NET Web API framework v2.0 are as follows:

  • Attribute Routing
  • External Authentication
  • CORS (Cross-Origin Resource Sharing)
  • OWIN (Open Web Interface for .NET) Self Hosting
  • IHttpActionResult
  • Web API OData

You can follow a good Web API new feature details on Top 5 New Features in ASP.NET Web API 2 here.

WCF Vs ASP.NET Web API?

Actually, Windows Communication Foundation is designed to exchange standard SOAP-based messages using variety of transport protocols like HTTP, TCP, NamedPipes or MSMQ, etc.

On the other hand, ASP.NET API is a framework for building non-SOAP based services over HTTP only.

For more details, please follow here.

Is it True that ASP.NET Web API has Replaced WCF?

It's a misconception that ASP.NET Web API has replaced WCF. It's another way of building non-SOAP based services, for example, plain XML or JSON string, etc.

Yes, it has some added advantages like utilizing full features of HTTP and reaching more clients such as mobile devices, etc.

But WCF is still a good choice for following scenarios:

  • If we intended to use transport other than HTTP, e.g. TCP, UDP or Named Pipes
  • Message Queuing scenario using MSMQ
  • One-way communication or Duplex communication

For a good understanding for WCF(Windows Communication Foundation), please follow WCF Tutorial.

MVC Vs ASP.NET Web API?

As in previous ASP.NET Web API Interview Questions, we discussed that the purpose of Web API framework is to generate HTTP services that reach more clients by generating data in raw format, for example, plain XML or JSON string. So, ASP.NET Web API creates simple HTTP services that renders raw data.

On the other hand, ASP.NET MVC framework is used to develop web applications that generates Views as well as data. ASP.NET MVC facilitates in rendering HTML easy.

MVC Vs Web API

For ASP.NET MVC Interview Questions, follow the link.

How to Return View from ASP.NET Web API Method?

(A tricky Interview question) No, we can't return view from ASP.NET Web API method. We discussed in the earlier interview question about the difference between ASP.NET MVC and Web API that ASP.NET Web API creates HTTP services that renders raw data. Although, it's quite possible in ASP.NET MVC application.

How to Restrict Access to Web API Method to Specific HTTP Verb?

Attribute programming plays its role here. We can easily restrict access to an ASP.NET Web API method to be called using a specific HTTP method. For example, we may require in a scenario to restrict access to a Web API method through HTTP POST only as follows:

C#
[HttpPost]
public void UpdateStudent(Student aStudent)
{
      StudentRepository.AddStudent(aStudent);
}

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

Yes, ASP.NET Web API is bundled with ASP.NET MVC framework but still it can be used with ASP.NET Web Form.

It can be done in three simple steps as follows:

  1. Create a Web API Controller
  2. Add a routing table to Application_Start method of Global.asax
  3. Make a jQuery AJAX Call to Web API method and get data

jQuery call to Web API for all CRUD (Create, Retrieve, Update, Delete) operations can be found here.

How Can We Provide an Alias Name for ASP.NET Web API Action?

We can provide an alias name for ASP.NET Web API action same as in case of ASP.NET MVC by using "ActionName" attribute as follows:

C#
[HttpPost]
[ActionName("SaveStudentInfo")]
 public void UpdateStudent(Student aStudent)
 {
       StudentRepository.AddStudent(aStudent); 
 }

In this ASP.NET Tutorial, we covered the most important Interview questions on ASP.NET Web API framework. Hopefully, it will be helpful for Web API developer Interview but along with these questions, do the practical implementation as much as you can. In Practical guide to ASP.NET Web API, you can find a good step by step approach for understanding and implementing ASP.NET Web API services.

Previous <<< ASP.NET Interview Questions - Part -5

Other Recommended Articles

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Emaratech
United Arab Emirates United Arab Emirates
Imran Abdul Ghani has more than 10 years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET(MCSD.NET) since 2005. You can reach his blogging at WCF Tutorials, Web Development, SharePoint for Dummies.

Comments and Discussions

 
Questionbest way to secure api Pin
Member 912997124-Feb-17 23:24
Member 912997124-Feb-17 23:24 
AnswerRe: best way to secure api Pin
Member 136151929-Jan-18 18:22
Member 136151929-Jan-18 18:22 
GeneralRe: best way to secure api Pin
frikrishna14-Feb-18 4:45
frikrishna14-Feb-18 4:45 
QuestionHow to add the custom header for End point in WCF using c# coding Pin
Member 118537847-Sep-15 18:56
Member 118537847-Sep-15 18:56 
GeneralMy vote of 5 Pin
Oscar R. Onorato13-Dec-14 14:08
Oscar R. Onorato13-Dec-14 14:08 
GeneralMy vote of 5 Pin
sandeep29725-Jul-14 0:53
sandeep29725-Jul-14 0:53 
Its very help full and refresh your understanding quickly.
GeneralRe: My vote of 5 Pin
Imran Abdul Ghani5-Jul-14 3:55
Imran Abdul Ghani5-Jul-14 3:55 
GeneralWell compiled Pin
CoderPanda6-May-14 21:12
professionalCoderPanda6-May-14 21:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.