Web API Interview Questions and Answers

web api interview questions In this write-up, I am going to go over one of the most frequently asked Web API Interview Questions and Answers.

Let start the Web API Interview Questions and Answers conversation with the most fundamental concern that asked in practically in all meetings i.e. What is ASP.NET Web API.

What is ASP.NET Internet API?

asp.net interviews

The term API means Application Programming Interface. ASP.NET Web API is a structure that makes it simple to build Internet API’s, i.e. HTTP based solutions in addition to the.NET Structure. ASP.NET Internet API is an excellent system for developing Restful services. These services can then be taken in by a wide variety of customers like

Mobile applications
Desktop computer applications

What is Rest?

rest api interview questions

REMAINDER stands for Representational State Transfer. This is an architectural pattern for exchanging information over a dispersed atmosphere. REST building pattern deals with each solution as a source and also a client can access these sources by utilizing HTTP method techniques like OBTAIN, POST, PUT, as well as DELETE.

What is Not Rest?

A method
A requirement
A replacement of SOAP

What are RESTful services?

rest api interview questions java

If you are getting ready for Web API Interviews then certainly you have to prepare this Web API Interview Questions.

REST stands for Representational State Transfer. The REST was first presented in the year 2000 by Roy Fielding as part of his doctoral dissertation. REMAINDER is a building pattern for trading the information over a dispersed environment. REST building pattern treats each solution as a resource and a client can access these resources by utilizing HTTP protocol approaches like GET, PUBLISH, PUT, and ERASE. The REST building pattern defines a collection of restraints that a system should abide by. Here are the REMAINDER restraints.

Client-Server restraint–.
This is the initial restraint. This restriction specifies that a Customer sends out a request to the web server and the server sends an action back to the customer. This separation of worries sustains the independent development of both client-side and also server-side reasoning. That indicates client application as well as server application should be established separately with no reliance on each other. A client must only recognize source URIs which’s all. Severs as well as clients may likewise be replaced and also created separately as long as the interface in between them is not modified.

Stateless restraint–.
The next restraint is the stateless restriction. The stateless constraint specifies that the interaction between the customer and the web server have to be stateless in between requests. This means that we must not be keeping anything on the server related to the client. The request from the customer must have all the essential information for the web server to procedure that demand. This ensures that each request can be treated separately by the server.

Cacheable restraint–.
Some data supplied by the web server like the checklist of products, or checklist of divisions in a company does not transform that usually. This constraint states that let the client understand the length of time this information is good for so that the client does not need to come back to the server for that data over and over once more.

Uniform User interface constraint–.
The consistent user interface constraint defines an interface between the client and also the server. To recognize the consistent user interface restriction, we need to comprehend what a source is as well as the HTTP verbs– OBTAIN, PUT, MESSAGE and also REMOVE. In the context of a REMAINDER API, resources commonly stand for data entities. The product, Staff member, Consumer, etc. are all resources. The HTTP verb (GET, PUT, BLOG POST, as well as ERASE) that is sent with each demand tells the API what to do with the resource. Each source is identified by a details URI (Attire Source Identifier).

Layered System-.
REST allows us to make use of a layered system architecture where we deploy the APIs in server A, and shop information on web server B and also authenticate requests in web server C. As an example, a client can not usually tell whether it is connected directly to the web server or to an intermediary in the process.

What are the distinctions between REST as well as SOAP?

rest api interview questions java

It is one of the most often asked Web API Interview Questions in Web API Interviews.

The distinction in between REST as well as SOAP is offered below:.

SOAP means Simple Item Accessibility Procedure whereas REST stands for Representational State Transfer.
The SOAP is an XML based method whereas REST is not a method yet it is a building pattern i.e. resource-based architecture.
SOAP has requirements for both stateless and state-full execution whereas REST is completely stateless.
SOAP applies message layout as XML whereas REST does not enforce message style as XML or JSON.
The SOAP message consists of an envelope which includes SOAP headers and also body to keep the real details we want to send out whereas REST makes use of the HTTP build-in headers (with a range of media-types) to save the info and also makes use of the HTTP GET, BLOG POST, PUT and also DELETE approaches to execute WASTE procedures.
SOAP utilizes interfaces and named operations to reveal the solution whereas to reveal sources (solution) REST utilizes URI as well as methods like (OBTAIN, PUT, ARTICLE, DELETE).
SOAP Performance is sluggish as compared to REST.

What are the Differences between WCF and also Web API? When to choose one over the various other?

WCF (Windows Communication Structure) is just one of the choices readily available in.NET for producing both SOAP as well as REST solutions. The trouble with WCF is that a great deal of configuration is needed to turn a WCF solution into a REMAINDER solution. So the more natural choice for producing REST services is ASP.NET Internet API, which is especially developed for this function.

WCF is more fit for building services that are transport/protocol independent. For example, we want to develop a single solution that can be consumed by 2 various clients– Allow’s state, a Java customer and.NET client. Java customer desires the transportation protocol to be HTTP and message layout to be XML for interoperability, whereas the.NET customer expects the procedure to be TCP as well as the message style to be binary for performance. For this scenario, WCF is the appropriate selection. What we need to do right here is produce a solitary WCF solution, and after that configure 2 endpoints one for every client (i.e. one for the Java client as well as the various other for the.NET client).

There is absolutely nothing wrong to make use of WCF to produce REST services. It’s simply that it’s a bit much more complicated as well as arrangement can be a frustration. If we are stuck with.NET 3.5 or we have an existing SOAP service we must sustain yet want to add REST to reach even more customers, then use WCF.

If we do not have the limitation of.NET 3.5 as well as we want to develop a brand-new restful service then utilize ASP.NET Internet API.

It is a structure utilized for building or creating service-oriented applications.
WCF can just be taken in by customers, which can comprehend XML. WCF supports methods like– HTTP, TCP, Named Pipeline and so on
Internet API. It is a structure which assists us to build/develop HTTP solutions.
Internet API is an open resource system.
It supports a lot of the MVC features which keep Internet API over WCF.

When do we require to select Web API?

asp net interview questions for experienced

Today, a web-based application is not enough to reach its consumers. Currently a day, Peoples end up being really wise; they are utilizing iPhone, mobile, tablets and so on gadgets in their life. These gadgets are having a lot of apps for making their life easy. In fact, we are relocating from the internet towards apps world.

So, if we such as to expose our solution data to the internet browsers as well as to all these contemporary gadgets apps in a quick as well as straightforward means, we ought to have an API which is compatible with browsers in addition to all these tools.

The ASP.NET WEB API is a great framework for structure HTTP services that can be taken in by a wide range of clients consisting of web browsers, mobiles, iPhone and tablets. Furthermore, INTERNET API is open source and a suitable system for structure REST-full solutions over the.NET Structure.

What are the advantages of using REST in WebAPI?

REST always used to make fewer data transfers between client and web server that makes REST a perfect for utilizing it in mobile applications. Web API supports HTTP protocol thus it reintroduces the old method of HTTP verbs for interaction.

What are the Differences in between WCF Rest and also Web API?

WCF Rest.
WebHttpBinding to be allowed for WCF Relax.
For every approach, there need to be features such as– “WebGet” and also “WebInvoke”.
For OBTAIN and MESSAGE verbs respectively.
Web API.
Unlike WCF Rest we can make use of complete functions of HTTP in Internet API.
Web API can be organized in IIS or in an application.

What are the benefits of using ASP.NET Web API?

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

It works the means HTTP functions using common HTTP verbs like GET, POST, PUT, DELETE, etc. for all CRUD procedures.
Complete support for routing.
Action produced in JSON or XML format utilizing MediaTypeFormatter.
It has the capability to be hosted in IIS as well as self-host outside of IIS.
Supports Model binding and Recognition.
Support for OData.

What new functions are presented in ASP.NET Internet API 2.0?

The brand-new features introduced in ASP.NET Internet API framework v2.0 are as follows:.

Attribute Routing.
External Verification.
CORS (Cross-Origin Resource Sharing).
OWIN (Open Web User interface for.NET) Self Hosting.
Web API OData.

What are the distinctions between ASP.NET MVC as well as ASP.NET Web API?

Below are a few of the differences between MVC and also Internet API.

MVC is utilized to develop an internet application, in which we can build web pages.
For JSON it will return JSONResult from an activity method.
All requests are mapped to the respective activity techniques.
Internet API.
This is used to develop a service utilizing HTTP verbs.
This returns XML or JSON to the customer.
All requests are mapped to actions using HTTP verbs.
There are adhering to differences between ASP.NET MVC and INTERNET API:.
MVC is made use of to produce internet applications that return both sights and data however ASP.NET INTERNET API is utilized to develop remainder full HTTP solutions with the very easy as well as basic way that returns only information, not watch.
WEB API helps to construct REST-full solutions over the.NET Framework and it likewise sustains content-negotiation which is not in MVC.
WEB API likewise deals with returning data in a particular format like JSON, XML or any other based upon the Accept header in the request. MVC only return information in JSON style making use of JsonResult.
In WEB API the request is mapped to the actions based on HTTP verbs but in MVC it is mapped to actions name.
We can blend INTERNET API as well as MVC controller in a solitary job to deal with advanced AJAX demands which may return information in JSON, XML or any others format and building a full-on HTTP solution. Commonly, this will certainly be called WEB API self-hosting.
In Addition, INTERNET API is lightweight architecture and except the internet application, it can also be made use of with smartphone applications.

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

It’s a mistaken belief that ASP.NET Internet API has replaced WCF. It’s another method of building non-SOAP based services, for instance, plain XML or JSON string, and so on

. Yes, it has actually some added advantages like using the complete functions of HTTP as well as reaching more customers such as mobile phones, and so on

. However WCF is still an excellent selection for the adhering to situations:.

1. If we meant to use transportation other than HTTP, e.g. TCP, UDP or Called Pipes.
2. Message Queuing situation using MSMQ.
3.One-way interaction or Duplex communication.

Describe media Formatters in Web API 2.

This Web API Interview Questions are asked nearly all Web API Interviews.

As we understand that internet API manages JSON and XML formats based on the Accept as well as Content-Type header values. Yet how does web API handles these various formats? The solution is by using Media Kind Formatters.

The Media-Type Formatters are courses which are responsible for serializing request/response information to make sure that web API can understand the request data style as well as send data in the layout which client expects.

Technically MediaTypeFormatter is an abstract class from which JsonMediaTypeFormatter as well as XmlMediaTypeFormatter classes inherit from. JsonMediaTypeFormatter takes care of JSON and also XmlMediaTypeFormatter handles XML.

How to return only JSON from ASP.NET Web API Service irrespective of the Accept header value?

Include the adhering to line in Register() method of WebApiConfig.cs data in App_Start folder. This line of code totally removes XmlFormatter which compels ASP.NET Internet API to always return JSON irrespective of the Accept header worth in the client demand. Use this strategy when we want our solution to sustain just JSON and also not XML.

With this change, regardless of the Accept header value (application/xml or application/json), the Web API solution is always going to return JSON.

config.Formatters.Remove( config.Formatters.XmlFormatter);.

Just how to return the only XML from ASP.NET Internet API Service irrespective of the Accept header worth?
Consist of the following line in Register() method of WebApiConfig.cs data in App_Start folder. This line of code entirely removes JsonFormatter which forces ASP.NET Internet API to always return XML irrespective of the Accept header value in the customer request. Utilize this technique when you want your solution to sustain only XML and also not JSON.

config.Formatters.Remove( config.Formatters.JsonFormatter);.
With this adjustment, regardless of the Accept header worth (application/xml or application/json), the Internet API service is constantly mosting likely to return XML.


Just how to return JSON instead of XML from ASP.NET Internet API Solution when a request is made from the internet browser?

web api interview questions pdf

So below is what we want the solution to do.

When a request is issued from the web browser, the web API service need to return JSON instead of XML.
When a request is issued from a tool like a fiddler the Accept header value must be appreciated. This indicates if the Accept header is readied to application/xml the solution ought to return XML as well as if it is set to application/json the service should return JSON.
There are 2 methods to achieve this.

Consist of the following line in Register() technique of WebApiConfig.cs data in App_Start folder. This informs ASP.NET Internet API to use JsonFormatter when a demand is made for text/html which is the default for the majority of internet browsers. The trouble with this approach is that the Content-Type header of the reaction is readied to text/html which is misleading.
config.Formatters.JsonFormatter.SupportedMediaTypes.Add( brand-new MediaTypeHeaderValue(” text/html”));.

Consist of the complying with class in WebApiConfig.cs file in App_Start folder.

Register Formatter:.
Place the adhering to line in Register() method of WebApiConfig.cs data in App_Start folder.

WEB API Interview Questions and Answers.

config.Formatters.Add( new CustomJsonFormatter());.
With these 2 modifications, when a demand is issued from the browser you will obtain JSON formatted information as well as the Content-Type header of the reaction is likewise set to application/json. If you are making use of devices like a fiddler and if you set Approve header to application/xml you will still obtain XML formatted information.


What is the difference between ApiController and Controller?

– Usage Controller to render your typical views.
– ApiController action just return information that is serialized as well as sent to the client.

public class TweetsController : Controller {

  // GET: /Tweets/


  public ActionResult Index() {

    return Json(Twitter.GetTweets(), JsonRequestBehavior.AllowGet);




public class TweetsController : ApiController {

  // GET: /Api/Tweets/

  public List<Tweet> Get() {

    return Twitter.GetTweets();



Call types of Action Results in Web API 2.

A Web API controller activity can return any of the following:.
– space – Return vacant 204 (No Content).
– HttpResponseMessage – Return vacant 204 (No Material).
– IHttpActionResult – Call ExecuteAsync to produce an HttpResponseMessage, after that convert to an HTTP reaction message.
– Some other kind – Compose the serialized return worth right into the feedback body; return 200 (OK).

Clarify briefly CORS( Cross-Origin Source Sharing)?

net web services interview questions

CORS (Cross-origin resource sharing) is a method that permits restricted resources on a web page to be asked for from one more domain name outside the domain name of which the very first source was offered. A website may easily attach cross-origin photos, manuscripts, stylesheets, iframes, as well as video clips. The same-origin security plan by default does not allow specific “cross-domain” requests, especially Ajax requests.
Cross-origin source sharing supplies a means by which an internet browser and also server can communicate to determine whether permitting the cross-origin demands are secure or otherwise.

What’s the difference in between OpenID and OAuth?

asp net web api 2.0

– OpenID is (mainly) for identification/authentication, so that stackoverflow.com recognizes that I own chris.boyle.name (or wherever) and also consequently that I am possibly the very same individual who had chris.boyle.name the other day and also gained some online reputation points.
– OAuth is developed for consent to take actions on your behalf, so that stackoverflow.com (or anywhere) can ask consent to, say, Tweet on your behalf automatically, without recognizing your Twitter password.

Web API Interview Questions and Answers

Leave a Reply

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

Scroll to top