Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
90 views

PDF Web Api Interview Questions - Compress

This document contains an introduction to web APIs and 42 interview questions about web APIs. Some key points: - Web APIs first emerged in the early 2000s to allow access to data from websites and online services. - A web API provides an interface for accessing data from a server via HTTP and supports formats like XML and JSON. It allows client applications and websites to access data. - Common return types from web APIs include any data type depending on requirements. HTTP methods like GET, POST, PUT determine return formats. - The document lists questions about web APIs, ASP.NET web APIs, REST vs SOAP, caching, security, error handling, testing APIs, and more. It provides an

Uploaded by

r.jegansaro
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

PDF Web Api Interview Questions - Compress

This document contains an introduction to web APIs and 42 interview questions about web APIs. Some key points: - Web APIs first emerged in the early 2000s to allow access to data from websites and online services. - A web API provides an interface for accessing data from a server via HTTP and supports formats like XML and JSON. It allows client applications and websites to access data. - Common return types from web APIs include any data type depending on requirements. HTTP methods like GET, POST, PUT determine return formats. - The document lists questions about web APIs, ASP.NET web APIs, REST vs SOAP, caching, security, error handling, testing APIs, and more. It provides an

Uploaded by

r.jegansaro
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Web API Int

Interview Questions
Questions

To view the live version of the


page, click here.

© Copyright by Interviewbit
Contents

Web API Basic Int


Intervie
ervieww Questions
1. Why is the Web API important?
2. What is Web
W eb API and why we use it ?
3. What are the main return types supported in Web API?
4. What is the difference between Web API and WCF?
5. Why to choose Web API over WCF?
6. What is different between REST API and RESTful API?
7. What are the advantages of using Rest in Web API?
8. What is REST and SOAP? What is different between them?
9. What is Web API 2.0?
10. Explain media type formatters.
11. Web API supports which protocol?
12. Which of the following Open-source libraries is used by WEB API for JSON
serialization?

13. What is XML and JSON?


14. What are Web API filters?
15. Who can consume Web API?
16. How to handle errors in Web API?
17. How to register an exception filter globally?
18. What is MVC? Write difference between MVC and Web API?

ASP.NET
ASP.NET Web API Int
Intervie
ervieww Questions
Questions

Page 1 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

ASP.NET
ASP.NET Web API Int
Intervie
ervieww Questions
Questions (.....Continued)

19. What is
i s ASP.NET
ASP.NET Web API?
20. What are the advantages of using
u sing ASP.NET
ASP.NET Web API?
21. What are new features used in ASP.NET Web API 2.0
22. What is the
th e use of HttpRespons
Ht tpResponseMessage?
eMessage?
23. What is the difference between ApiController and Controller?
24. What do you mean by Caching and What are its types?
25. WCF is replaced by ASP.NET Web API. True/False?
26. What are the main return types supported in ASP. Net Web API?
27. What is
i s ASP.NET
ASP.NET Web API routing?
rout ing?
28. HOW to secure ASP.NET
ASP.NET Web API?
29. What are Exception filters in ASP.NET Web API?
30. Which .NET framework supports ASP.NET Web API?
31. What is HttpConfiguration in Web API?
32. Can we return View from ASP.NET Web API method?
33. What is content negotiation in ASP.Net Web API?
34. Difference between HTTP
HT TP GET vs HTTP
HTT P Post?
Post?
35. What is CORS in Web API?
36. Name method that validates all controls on page?
37. What parameters can be passed in the URL of API?
38. What is the use of DelegatingHandler?

Page 2 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

ASP.NET
ASP.NET Web API Int
Intervie
ervieww Questions
Questions (.....Continued)

39. Web API uses which library for JSON serialization?


40. Explain method to handle error using HttpError in Web API?
41. How to unit test Web API?

Conclusion
42. Conclusion

Page 3 © Copyright by Interviewbit


Let's get Started

Introduction to Web API:

7 Feb 2000: Web API was first introduced in the wild along with the introduction
of Salesforce on 7th Feb. The Salesforce company officially launched its API at
IDG Demo 2000 conference.
20 Nov 2000: eBay launched their eBay API on 20 November 2000 with eBay
Developers Program.
16 July 2002: Amazon launched Amzon.com web services on 16 July 2002 that
allows developers to implement content and features of amazon.com into their
own websites.
Web API was first started in early e-commerce on the Internet. At present, web APIs
are still recognized as a hobby by mainstream businesses.

Web API Basic Int


Intervie
ervieww Questions
1. Why is the Web API important
important??
Web API is generally considered as a service that basically provides us information
inform ation or
data from the server. It is very important because of the following reasons:

Page 4 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

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,
U I/UX, increases
interest in the company’
com pany’ss product and services, increases website
website traffic.
traff ic.

2. What is Web API and why we use it ?

Page 5 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

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
services t ool that can be used to push data to a server and can be access
accessed
ed by
server code. It can be built or developed using various technologies like java,
ASP.NE
ASP.NETT, 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
A SP.NET
.NET MVC and different
differen t types of web applications such as
ASP.NET
ASP .NET WebForm
WebForms. s.
If one wants to create resource-oriented services
services,, then Web API services are
considered the best.
It also helps to develop REST-ful services and SOAP-based services.

3. What are the main return types supported


supported in Web API?

Page 6 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

It does not have any specific data type. It can return data of any type depending upon
the business requirement.
requirement . There are many
man y HTTP methods
met hods like GET,
GET, POST,
POST, PUT,
PUT, etc.,
which can return data in different formats depending upon the use case.

4. What is the difference between Web API and WCF?


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
simply extends or increases the functionality
functionalit y of web browsers
whereas Server API simply extends or increases
incr eases the functionality of web server.
server.

Page 7 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

Web API WCF

It is used to develop both SOAP


S OAP--
It is used to deploy only
based services and
and RESTful
REST ful
services. SOAP-based services.

It supports various MVC


It does not support any
features such as routing, model
MVC features.
binding, etc.

It supports various
It only supports HTTP protocol. protocols such as HTTP,
UDP,, custom transport.
UDP

It is considered best for It supports only limited


developing RESTFUL services. RESTFUL services.

It is good when one wants to It is good for creating


expose an expensive range of services that uses expedite
clients such as iPhones, transport channels such as
browsers, mobile phones, TCP, UDP, Named pipes,
tablets, etc. etc.

It offers TEXT, Binary


encoding support, MTOM
It offers support for UTF-8
(Message Transmiss
Transmission
ion
encoding format.
Optimization Mechanis
Mechanism),
m),
etc.

5. Why to choose Web API over WCF?


Web API is considered the best choice over WCF because of the following reasons:

Page 8 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

Web API uses all features of HTTP


HT TP such as URIs, request/response
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.
A PI.
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.

6. What is different
different between REST API and RESTful API?

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
HT TP protocol using its verbs such as GET, DELETE,
DELET E, POST
POST,,
PUT.
RESTful API: It is simply referred to as web services executing such as architecture.

Page 9 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

REST API RESTful API

REST is an
architectural pattern RESTful API is used to implement
used for creating web that pattern.
services.

The data format of


The data format of RESTful is based
REST is based on
on JSON, HTTP, and Text.
HTTP.

Working of URL is
Working of RESTful is based on
based on request and
REST applications.
response.

It is more user-friendly
and highly adaptable
It is too flexible.
to all business
enterprises and IT.

It is required to
It simply follows REST
develop APIs that
infrastructure that provides
allow interaction
interoperability among different
among clients and
servers. systems on the whole network.

7. What are the advan


advantages
tages of using
using Rest in Web API?
REST is very important and beneficial in Web API because of the following reasons:

Page 10 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

It allows less data transfer between client and server


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.
server.
It uses simple HTTP calls for inter-machine communication rather than using
more complex options like CORBA, COM+, SOAP, or RPC.

8. What is REST and


and SOAP? What
What is different
different between them?
REST (Representat
(Representational
ional Stat
tate
e Transfer)
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":"M
{"city":"Mumbai","state":"Maharashtra"}
aharashtra"}

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
version="1.0"?>
"?>
<SOAP-ENV:Envelope
<SOAP-ENV:Envelope xmlns:SOAP-EN
xmlns:SOAP-ENV="http://www
V="http://www.w3.org/2001/1
.w3.org/2001/12/soap-envelo
2/soap-envelope"
pe" SOAP-ENV:e
<soap:Body>
<Demo.guru99WebService
<Demo.guru99WebService xmlns="http:/
xmlns="http://tempuri.org/"
/tempuri.org/">
> <EmployeeID>int</EmployeeID
<EmployeeID>int</EmployeeID>
>
</Demo.guru99WebService>
</soap:Body>
</SOAP-ENV:Envelope>

Page 11 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

REST SOAP

It is basically an It is basically a messag


m essaging
ing
architectural pattern. protocol.

It usually works with


various text formats
It only works with XML formats.
such as plain text,
HTML, JSON, XML, etc.

It has some specifications for both


It is totally
t otally stateless. stateless and stateful
implementation.

Its performance is
Its performance is slower as
faster as compared to
compared tot o REST.
REST.
SOAP.

It uses WSDL (Web Service


It uses XML and JSON to Description Language) for
send and receive data. communication among
consumers or users
u sers and providers.

SOAP includes built-in error


REST has to resend handling for communications
comm unications
transfer whenever it
errors using WS-
determines any errors.
ReliableMessaging
ReliableMess aging specification.

It calls services using It calls services by calling RPC


the URL path. (Remote Procedure Call) method.

Page 12 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

9. 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
AS P.NET Web API using OAuth 2.0
Support for Cross
Cross-Origin
-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.

10. Expl
Explain
ain 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.
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.

Page 13 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

Medi a Type Formatter Class MIME Type Descrip

Handles
application/json,
JsonMediaTypeFormatter JSON
text/json format

application/xml, Handles
XmlMediaTypeFormatter
text/json XML for

Handles
application/x- HTM for
FormUrlEncodedMediaTypeFormatter www-form- URL-
urlencoded encode
data

Handles
model-
application/x- bound
JQueryMvcFormUrlEncodedFormatter www-form- HTML fo
urlencoded URL-
encode
data

Page 14 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

11. Web API supports which protocol?


Web API generally supports only HTTP protocol.

12. Which of the following Open-source libraries is used by WEB


API for JSON
J SON serialization?
serializatio n?
Json.NET library is generally used by Web API for JSON serialization.

13. What is XML and JSON?


XML (Extensible Markup Language):

It is especially designed
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):

Page 15 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

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.

14. What are Web API filters?


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
Authenticati on Filt er: It handles authentication and authenticates HTTP
Filter:
requests. It also helps to authenticate user detail. It checks the identity of the
user.
Authoriza
Autho tion Filter: It handles authorization. It runs before controller action.
rization
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.
AuthorizeAttri
Autho rizeAttribute
bute 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 aer controller action executes.
It is simply a way to add extra
ext ra functionality
functio nality to Web
W eb API services.
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
of other filterfor
filters or individual
controller action
level filter. It is simply used to modify the behavior
methods.

Page 16 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

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

16. How to handle


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.

17. How to register an exc


excep
eptio
tionn filt
filter
er globally?
One can register exception filter globally using following code:
GlobalConfiguration.Configu
GlobalConfiguration.Configuration.Filters
ration.Filters.Add
.Add (new
MyTestCustomerStore.NotImpl
MyTestCustomerStore.NotImplExceptionFilt
ExceptionFilterAttribute())
erAttribute());
;

18. What is MVC? Write differenc


difference
e between
between MVC and Web API?

Page 17 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

MVC (Model, View, and Controller) is basically an application design modelm odel that
comprises three interconnect
in terconnect parts
part s I.e., model, view
view,, and controller.
cont roller. 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.

MVC Web API

It can be used to build Web It is used to build HTTP


applications that reply as both services that reply only
data and views
views.. as data.

It returns data in
It returns data in JSON format by
using JSONRes
JS ONResult.
ult. different formats such as
JSON, XML, etc.

It does not support


It supports content negotiation,
content negotiation, self-
self-hosting.
hosting.

It is very helpful in
It is not able to build REST-full
creating REST-full
services.
services.

It returns REST
It returns a view (HTML).
responses.

Page 18 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

ASP.NET
ASP.NET Web API Int
Intervie
ervieww Questions
Questions
19. What is ASP
ASP.N
.NET
ET Web API?
ASP stands for Active server pages. ASP.NET
ASP.NET is an updated version of legacy ASP.
ASP. It is a
framework that is used for developing HTTP services to provide responses to client
requests. It can be accessed in different applications on different platforms. It is
provided by Microso open-source technology for developing and consuming HTTP-
based services
services on top of .NET Framework.
Fr amework. It is very easy to build HTTP services
services using
ASP.NET
ASP .NET Web API. These services can be used by different clients as given below:

Desktop Applications
Mobile Applications
IOTs
Browsers

20. What are the advantages of using ASP


ASP.N
.NET
ET Web API?
Some of the core advantages of using ASP.NET Web API are given below:

Page 19 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

It provides the best platform for developing RESTful applications on .NET


Framework.
It works the same way that HTTP works with help h elp of HTTP
HT TP verbs such as GET,
GET,
POST,, PUT,
POST PUT, DELETE
DELE TE for all crud operations.
It provides enough flexibility in Web API creation.
It completely supports routing.
It also supports model binding, validation, Odata (Open Data Protocol) that
allows creation and consumption of RESTful APIs.
It has the ability to develop custom help and test pages with help of ApiExplorer.
One can develop non-SOAP
no n-SOAP-based
-based services such
such as plain XML, JSON strings, etc.
et c.
It also increases the TDD (Test Data-Driven)
Data-Driven) approach in i n the development
developm ent of
RESTful services.

21. What are new feat


features
ures used in ASP
ASP.N
.NET
ET Web API 2.0

ASP.NET
ASP.NET Web API includes a number
num ber of new
n ew exciting features
featu res as given below:
Attribute Routing
CORS (Cross-Origin Resource Sharing)
OWIN (Open Web Interface for .NET) self-hosting
IHttpActionResult
Web API OData

22. What is the use of HttpResponseMessag


HttpResponseMessage?
e?
It is used to set response values such as header and status control.
contr ol. It simply allows us
to work with HTTP protocol. It represents HTTP response messages that encapsulate
data and status code.

Page 20 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

// GetEmployee action
public HttpResponseMessage GetEmployee(int id)
{
Employee emp = EmployeeCont
EmployeeContext.Employees
ext.Employees.Where(e
.Where(e => e.Id == id).FirstOrD
id).FirstOrDefault();
efault();
if (emp != null)
{
return Request.Crea
Request.CreateResponse<Emp
teResponse<Employee>(HttpSt
loyee>(HttpStatusCode.OK,
atusCode.OK, emp);
} else
{
return Request.Crea
Request.CreateErrorRespons
teErrorResponse(HttpStatusC
e(HttpStatusCode.NotFound,
ode.NotFound, "Employee N
}
}

23. What is the differen


difference
ce between ApiController and
Controller?
ApiController: It is used to return data that is arranged in series and then sent to the
client.

public class TweetsController : ApiController


{
// GET: /Api/Tweets/
public List<Tweet> Get()
{
return Twitter.GetTw
Twitter.GetTweets();
eets();
}
}

Controller: It is used to provide normal views.

public class TweetsController : Controller


{
// GET: /Tweets/ [HttpGet] public ActionResult Index()
{
return Json(Twitter.G
Json(Twitter.GetTweets(),
etTweets(), JsonRequestBe
JsonRequestBehavior.AllowG
havior.AllowGet);
et);
}
}

24. What do
do you mean by Cac
Caching
hing and What are its types?

Page 21 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

Caching is basically a technique or process of storing data somewhere or in the cache


for future requests. The cache is a temporary storage area. Caching keeps all
frequently or recently accessed files or data in the cache memory and accesses them
from the cache itself rather than actual address of data or files. The cache interface
simply improves the storage mechanism for request/response object pairs that are
being cached.

Advantag
Advantages
es of Caching:

It is considered the best solution to ensure that data is served where it is needed
to be served that too at a high level of efficiency which is best for both client and
server.
It delivers web objects faster to the end-user
end-user..
It reduces load time
tim e on the
t he website server.
server.
It leads to faster execution of any process.

It decreases network costs.


Typess of Caching:
Type C aching:
There are basically three types of caching as given below:

Page Caching
Data Caching
Fragment Caching

25. WCF is replaced by ASP


ASP.N
.NET
ET Web API. True/False?
True/False?

Page 22 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

WCF: It is a framework used for developing SOAP (Service Oriented Applications


Protocols). It also supports various transport protocols
prot ocols as given above.
ASP.NET
ASP .NET Web
Web API: It is a framework
fr amework used
u sed for developing non-SOAP
non-S OAP-based
-based services.
services. It
is limited to HTTP
HTT P-based services.
services.

No, it's not


no t true that ASP
AS P.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
non-SOAP -based services
services such as XML, JSON,
J SON, etc. WCF is
i s still considered a better
choice if one has their service using HTTP as the transport and they want to move to
some other
oth er transport
tran sport like TCP
TCP,, NetTCP
NetT CP,, MSMQ,
M SMQ, etc.
et c. WCF also allows one-way
communication or duplex communication.

26. What are the main return types supporte


supportedd in ASP
ASP.. Net Web
API?
It supports the following return types:
HttpResponseMessage
IHttpActionResult
Void
Other types such as string, int, etc.

27. What is ASP


ASP.N
.NET
ET Web
Web API routing?
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.

Page 23 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

There are basically two ways to implement routing in Web API as given below:
tion-based routing: Web API supports convention-based routing. In this type
Convention-based
Conven
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.

28. HOW to secure ASP


ASP.N
.NET
ET Web API?

Page 24 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

Web API has become key to programming web-based interactions. It can be accessed
by anyone who knows the URL. Therefore, they have become targets for hackers. One
needs to secure Web API by controlling Web API and by deciding who can and who
cannot have access to Web API. There are basically two ways or techniques that make
our Web API more secure.

on: It is a process that helps to identify and check users by their


Authentication:
Authenticati
credentials such as password,
password, username, etc. To have access to the web API, firstly
user credentials are needed to be passed in the request header. If user credentials are
not passed into the request header, then the server returns 401 status code
(unauthorized). The best authentication to be used is OAuth 2.0.

tion: It is a process that helps to decide whether or not a user has access to
Authorization:
Authoriza
perform an action. Authorization filters are used
used to implement authorization.

29. What are Exc


Excep
eptio
tionn filt
filters
ers in ASP
ASP.N
.NET
ET 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.

30. Which .NE


.NETT framew
framework
ork supports
supports ASP
ASP.NE
.NETT Web
Web API?

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

31. What is HttpCo


HttpConfigur
nfiguration
ation in Web API?
It is considered as the main class that includes different properties with help of which
one can override the default behavior of Web API.

Some properties are given below:

Page 25 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

DependencyResolver: It sets or gets a dependency resolver for


fo r dependency
injection.
Services: It gets web API services.
ParameterBindingRules: It gets a collection of rules for how parameters should
be bound.
MessageHandlers: It sets
sets or gets message handlers.
handlers.
Formatters: It sets or gets media-type formatters.

32. Can we
we return View fro
fromm ASP
ASP.N
.NET
ET 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.

33. What is content negotiati


negotiation
on in ASP
ASP.N
.Net
et Web
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.

34. Differenc
Difference
e between HTTP GET vs
vs HTTP Post?
Post?

Page 26 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

HTTP (HyperText Transfer Protocol) simply manages request


request-response
-response between
client and server
server.. It works as a request-response
request-response protocol between client and server
server..

HTTP GET: This method is used to get information or data from a respective server at
a specified URL.

Example:
GET/RegisterStudent.asp?user=value1&pass
GET/RegisterStudent.asp?user=value1&pass=value2
=value2

HTTP POST: This method is used to send data or information to respective servers.

Example:
POST/RegisterStudent.asp HTTP/1.1
Host: www
www.guru99.com
.guru99.com
user=value1&pass=value2

Page 27 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

HTTP GET HTTP POST

Its parameters are Its parameters are included in the


included in the URL. body.

This method is used


to request data from
This method is used to send data to a
specified resources
server to create or update resources.
and has no other
effect.

It carries request parameters in the


It carries a request
message body that make it a more
parameter
secure way of sending data or
appended in the URL information from the client to the
string.
server.

Request method
Request method using POST is not
using GET is
cacheable.
cacheable.

GET requests are


Post request is safer than GET.
less safe than POST.

There is a restriction
on data type in GET There are no restrictions on data type
method and only in this method and binary data is also
ASCII characters are allowed.
allowed.

Data is visible to Data is not displayed in the URL. It is


everyone in the URL. present in the payload.

Page 28 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

35. What is CORS in Web API?


CORS (Cross-Origin
(Cross-Origin Resource Sharing)
Shari ng) is basically a mechanism
m echanism 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
(Sam e 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.

36. Name method that validates


validates all
all con
controls
trols on page?
Page.Validate()

37. What par


parameters
ameters can be passed in the URL of API?
API?
Context keys, documents keys, or anything that initiates API to hit the exact end-
point are few parameters that one can pass in the URL to define the complete end-
point.

38. What is the use of DelegatingHand


DelegatingHandler?
ler?

Page 29 © Copyright by Interviewbit


Web API Intervie
Interview
w Questions

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.

39. Web API uses


uses which libr
library
ary for JSON serialization?

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

40. Expl
Explain
ain method to handle
handle error using HttpError in Web API?
CreateErrorResponse is an extension method that can be used in Web API controller
methods to return error codes and error messages. It creates an HttpError object and
then wraps it inside
in side an HttpResponseMessage
HttpResponseMessage object.

41. How to unit test Web API?

Using Web
basically API tools
a free like Fiddler,
debugging proxy we can browser
for any perform unit
that testing in Web
can be used toAPI. Fiddler
compose is
and
execute various HTTP
HTT P 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.

Conclusion
42. Conclusion
Web API is an extensible framework that serves us information from the server and is
used for developing ASP
AS P.NET
.NET.. It is totally based on Http and is easy to define,
def ine, expose
and consume in a REST-ful way. It is considered an ideal platform for developing
RESTful applications on .NET framework. From the above Web API interview
questions and answers, you can learn more about Web API, its importance, its
benefits, etc.

Page 30 © Copyright by Interviewbit


Links to More Interview
Questions

C Interview Questions Php Interview Ques tions C Sharp Interview Questions

Web Api Interview Hibernate Intervi


I nterview
ew Node Js Interview Questions
Questions Questions

Cpp In
Interview Qu
Questions Oops In
Interview Qu
Quest
stiions Devops In
Interview Qu
Questions

Machine Learning Intervi


I nterview
ew Dock
Docker
er Int
Inter
ervi
view
ew Que
Questi
stions
ons Mysql
Mysql Int
Inter
ervvie
iew
w Quest
Questio
ions
ns
Questions

Css In
Intterview Qu
Que
est
stiion
onss Larravel In
La Intter
ervview Que
uest
stiion
onss Asp
Asp Ne
Nett In
Intterview Qu
Que
est
stiion
onss

Djan
Django
go In
Inte
terrview Qu
Quest
estiion
onss Dott Net
Do Net In
Inte
terrview Qu
Quest
estiion
onss Kub
uber
erne
nete
tess Inte
Interrview
Questions

Operating System Intervi


I nterview
ew React Native Interview Aws Interview Questions
Questions Questions

Git Interview Quest


stiions Java 8 Interview Questions Mongodb Interview
Questions

Dbms
Dbms In
Intter
ervview Qu
Ques
esttion
onss Spring Bo
Spr Boot
ot In
Inte
terrview Power Bi Interview Questions
Questions

Pl Sql
Sql In
Intter
ervview Qu
Ques
esttion
onss Tabl
blea
eau
u In
Intter
ervview Linux Interview Questions
Questions

Ansi
Ansibl
ble
e In
Intter
ervview Qu
Ques
esti
tion
onss Javva In
Ja Intter
ervview Qu
Ques
esttion
onss Jenk
Jenkiins In
Inte
terrview Qu
Ques
esti
tion
onss

Page 31 © Copyright by Interviewbit

You might also like