Web API Interview Questions
Web API Interview Questions
© Copyright by Interviewbit
Contents
Conclusion
42. Conclusion
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 that can be used to push data to a server and can be accessed by
server code. It can be built or developed using various technologies like java,
ASP.NET, etc.
It does not have any specific data type. It can return data of any type depending upon
the business requirement. There are many HTTP methods like GET, POST, 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 extends or increases the functionality of web browsers
whereas Server API simply extends or increases the functionality of web server.
It supports various
It only supports HTTP protocol. protocols such as HTTP,
UDP, custom transport.
Web API uses all features of HTTP such as URIs, 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.
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.
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
systems on the whole network.
servers.
{"city":"Mumbai","state":"Maharashtra"}
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"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope" SOAP-ENV:en
<soap:Body>
<Demo.guru99WebService xmlns="http://tempuri.org/"> <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 to REST.
SOAP.
Handles
application/json,
JsonMediaTypeFormatter JSON
text/json
format
application/xml, Handles
XmlMediaTypeFormatter
text/json XML form
Handles
application/x- HTM form
FormUrlEncodedMediaTypeFormatter www-form- URL-
urlencoded encoded
data
Handles
model-
application/x- bound
JQueryMvcFormUrlEncodedFormatter www-form- HTML fo
urlencoded URL-
encoded
data
MVC (Model, View, and Controller) is basically an application design model that
comprises three interconnect parts I.e., model, view, and controller. 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
different formats such as
using JSONResult.
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.
// GetEmployee action
public HttpResponseMessage GetEmployee(int id)
{
Employee emp = EmployeeContext.Employees.Where(e => e.Id == id).FirstOrDefault();
if (emp != null)
{
return Request.CreateResponse<Employee>(HttpStatusCode.OK, emp);
} else
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee No
}
}
Advantages 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.
It reduces load time on the website server.
It leads to faster execution of any process.
It decreases network costs.
Types of Caching:
There are basically three types of caching as given below:
Page Caching
Data Caching
Fragment Caching
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.
26. What are the main return types supported in ASP. Net Web
API?
It supports the following return types:
HttpResponseMessage
IHttpActionResult
Void
Other types such as string, int, etc.
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.
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.
Authorization: It is a process that helps to decide whether or not a user has access to
perform an action. Authorization filters are used to implement authorization.
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=value2
HTTP POST: This method is used to send data or information to respective servers.
Example:
POST/RegisterStudent.asp HTTP/1.1
Host: www.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.
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.NET. It is totally based on Http and is easy to define, 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.
Css Interview Questions Laravel Interview Questions Asp Net Interview Questions