PDF Web Api Interview Questions - Compress
PDF Web Api Interview Questions - Compress
Interview Questions
Questions
© Copyright by Interviewbit
Contents
ASP.NET
ASP.NET Web API Int
Intervie
ervieww Questions
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?
ASP.NET
ASP.NET Web API Int
Intervie
ervieww Questions
Questions (.....Continued)
Conclusion
42. Conclusion
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 (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.
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.
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.
It supports various
It only supports HTTP protocol. protocols such as HTTP,
UDP,, custom transport.
UDP
6. What is different
different between REST API and RESTful API?
REST is an
architectural pattern RESTful API is used to implement
used for creating web that pattern.
services.
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.
{"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>
REST SOAP
Its performance is
Its performance is slower as
faster as compared to
compared tot o REST.
REST.
SOAP.
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.
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
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.
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 aer 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.
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.
It returns data in
It returns data in JSON format by
using JSONRes
JS ONResult.
ult. different formats such as
JSON, XML, etc.
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.
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
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
// 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
}
}
24. What do
do you mean by Cac
Caching
hing and What are its types?
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.
Page Caching
Data Caching
Fragment Caching
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.
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.
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.
.NET Framework 4.0 generally supports the first version of ASP.NET Web API. Aer
that, .NET Framework 4.5 supports the latest version of web API i.e., ASP.NET Web API
2.
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.
34. Differenc
Difference
e between HTTP GET vs
vs HTTP Post?
Post?
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
Request method
Request method using POST is not
using GET is
cacheable.
cacheable.
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.
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.
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.
Cpp In
Interview Qu
Questions Oops In
Interview Qu
Quest
stiions Devops In
Interview Qu
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
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