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

Top 20 ASP - NET Web API Interview Questions

ASP.NET Web API is a framework provided by the Microsoft with which we can easily build HTTP services that can reach a broad of clients, including browsers, mobile, IoT devices, etc. ASP.NET Web API provides an ideal platform for building RESTful applications on the .NET Framework.

Uploaded by

AJIT SAMAL
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
339 views

Top 20 ASP - NET Web API Interview Questions

ASP.NET Web API is a framework provided by the Microsoft with which we can easily build HTTP services that can reach a broad of clients, including browsers, mobile, IoT devices, etc. ASP.NET Web API provides an ideal platform for building RESTful applications on the .NET Framework.

Uploaded by

AJIT SAMAL
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Top 20 ASP.

NET Web API Interview


Questions
ASP.NET Web API is a framework provided by the
Microsoft with which we can easily build HTTP
services that can reach a broad of clients,
including browsers, mobile, IoT devices, etc.
Introduction ASP.NET Web API provides an ideal platform for
building RESTful applications on the .NET
Framework.
ASP.NET Web API is a framework provided by the
Q- 1 What is Microsoft with which we can easily build HTTP
services that can reach a broad of clients,
ASP.NET Web including browsers, mobile, IoT devices, etc.
ASP.NET Web API provides an ideal platform for
API? building RESTful applications on the .NET
Framework.

Web API is a Framework to build HTTP Services that
can reach a board of clients, including browsers,
mobile, IoT Devices, etc. and provided an ideal
Q:- 2 What is platform for building RESTful applications. It is limited
to HTTP based services. ASP.NET framework ships out
the difference with the .NET framework and is Open Source. WCF i.e.
between Windows Communication Foundation is a framework
used for building Service Oriented applications (SOA)
ASP.NET Web and supports multiple transport protocol like HTTP,
TCP, MSMQ, etc. It supports multiple protocols like
API and WCF? HTTP, TCP, Named Pipes, MSMQ, etc. WCF ships out
with the .NET Framework. Both Web API and WCF can
be self-hosted or can be hosted on the IIS Server.
It totally depends upon the requirement. Choose
ASP.NET Web API is you want only HTTP based
Q:-3 When to services only as Web API is a lightweight
prefer ASP.NET architecture and is good for the devices which
have limited bandwidth. We can also create the
Web API over REST services with the WCF, but that requires lots
of configuration. In case, if you want a service
WCF? that should support multiple transport protocol
like HTTP, UDP, TCP, etc. then WCF will be a better
option.
Q:-4 Which .NET First Version of ASP.NET Web API is introduced in
.NET Framework 4. After that, all the later
Framework versions of the .NET Framework supports the
supports ASP.NET Web API.

ASP.NET Web
API?
Q-5 Can we
consume ASP.NET
Web API in Yes, we can consume ASP.NET Web API in the
applications created using another language than
applications .NET but that application must have
access/supports to the HTTP protocol.
created using
other than .NET?
Q-6 What is the ASP.NET MVC is used to create a web application
difference which returns both data as well as View whereas
Web API is used to create HTTP based Services
between ASP.NET which only returns data not view. In an ASP.NET
MVC application MVC application, requests are mapped to Action
and ASP.NET Web Methods whereas in the ASP.NET Web API
request is mapped to Action based on the Action
API application? Verbs.
REST stands for the Representational State Transfer. This term is
coined by the Roy Fielding in 2000. RESTful is an Architectural
style for creating loosely couple applications over the HTTP. In
order to make API to be RESTful, it has to adhere the around 6
constraints that are mentioned below:
• Client and Server Separation: Server and Clients are clearly
Q:-7 What are the isolated in the RESTful services.
• Stateless: REST Architecture is based on the HTTP Protocol and
RESTful Services? the server response can be cached by the clients, but no client
context would be stored on the server.
• Uniform Interface: Allows a limited set of operation defined
using the HTTP Verbs. For eg: GET, PUT, POST, Delete etc.
• Cacheable: RESTful architecture allows the response to be
cached or not. Caching improves performance and scalability.
• Code-On-Demand
• Layered System
The following features have been
introduced in ASP.NET Web API 2.0:
Q-8 What are the new • Attribute Routing
features introduced in • CORS (Cross-Origin Resource Sharing)
ASP.NET Web API 2.0? • OWIN (Open Web Interface for .NET)
self-hosting
• IHttpActionResult
• Web API OData etc.
Q-9 Can we return No, Web API does not return View but
View from Web they return the data. APIController is
meant for returning the data. So, if you
API? need to return a view from the controller
class, then make sure to use or inherit
the Controller class.
Q:-10 Does No, ASP.NET Web API didn’t replace WCF
ASP.NET Web API Service as it is only used for creating
RESTful Service i.e. non-SOAP based
replace the WCF? service.
In RESTful service, we can perform all types of
CRUD (Create, Read, Update, Delete) Operation.
In REST architecture, it is suggested to have a
specific Request Verb or HTTP verb on the
Q-11 What is specific type of the call made to the server.
Popular Request Verbs or HTTP Verbs are
Request Verbs or mentioned below:
• HTTP Get: Used to get or retrieve the
HTTP Verbs? resource or information only.
• HTTP Post: Used to create a new
resource on the collection of resources.
• HTTP Put: Used to update the existing
Response
• HTTP Delete: Used to Delete an existing
resource.
Q-12 What are HTTP Status Code Is 3-digit integer in
HTTP Status which the first digit of the Status-Code
Codes? defines the class of response. Response
Header of each API response contains
the HTTP Status Code. HTTP Status
Codes are grouped into five categories
based upon the first numbe
S. No. HTTP Status Code Description

1 1** Information

2 2** Success

3 3** Redirection

4 4** Client Side Error

5 5** Server Side Error

• Table: HTTP Status Code with Description


• Some of the commonly seen HTTP Status Codes are: 200
(Request is Ok), 201 (Created), 202 (Accepted), 204 (No Content),
Continuing to Q- 12 301 (Moved Permanently), 400 (Bad Request), 401
(Unauthorized), 403 (Forbidden), 404 (Not Found), 500 (Internal
Server Error), 502 (Bad Gateway), 503 (Service Unavailable) etc.
When Web API calls a method on a
controller, it must set the values for the
parameters, this particular process is
known as Parameter Binding. By Default,
Web API uses the below rules in order to
Q-13 What is bind the parameter:
Parameter Binding in • FromUri: If the parameter is of “Simple”
type, then Web API tries to get the value
ASP.NET Web API? from the URI. Simple Type includes.Net
Primitive type like int, double, etc.,
DateTime, TimeSpan, GUID, string, any
type which can be converted from the
string type.
• FromBody: If the parameter is of
“Complex” type, then Web API will try to
bind the values from the message body.
Content Negotiation is the process of selecting
the best representation for a given response
when there are multiple representations
available. Two main headers which are
Q-14 What is responsible for the Content Negotiation are:
Content Negotiation • Content-Type
in Web API? • Accept
The content-type header tells the server about
the data, the server is going to receive from
the client whereas another way to use Accept-
Header, which tells the format of data
requested by the Client from a server. In the
below example, we requested the data from
the server in JSON format.
Media-Type formatter is an abstract class
from which JsonMediaTypeFormatter
Q-15 What is Media- (handle JSON format) and
XmlMediaTypeFormatter (handle XML
Type Formatter in format) class derived from. Media-Type
ASP.NET Web API? formatter are classes responsible for
serializing the response data in the
format that the client asked for.

Q-16 What is the Web API provided a built-in authorization
filter, i.e. Authorize Attribute. This filter
use of Authorize checks whether the user is authenticated
Attribute? or not. If not, the user will see 401
Unauthorized HTTP Status Code.
Basic HTTP Authentication is a
mechanism, where the user is
Q-17 What is Basic authenticated through the service in
HTTP which the client pass username and
password in the HTTP Authorization
Authentication? request headers. The credentials are
formatted as the string
“username:password”, based encoded.
Q-18 How Web API In ASP.NET Web API, HTTP request maps
Routes HTTP request to the controller. In order to determine
to the Controller which action is to invoke, the Web API
framework uses a routing table.
ASP.NET MVC?
We can do Web API Versioning in the
Q-19 In How many following ways:
ways we can do Web • URI
API Versioning? • Query String Parameter
• Custom Header Parameter
• Accept Header Parameter
Exception handling is a technique to
Q-20 What is handle runtime error in the application
code. In multiple ways we can handle
Exception the error in ASP.NET Web API, some of
handling? them are listed below:
• HttpResponseException
• HttpError
• Exception Filters etc.
I hope these questions and answers
will help you to crack your Web API
Interview. These interview Questions
have been taken from our new
released eBook ASP.NET Web API
Interview Questions.
Summary This eBook has been written to
make you confident in Web API with a
solid foundation. It's would be equally
helpful in building REST API using
ASP.NET Web API and integrating it
with your real projects.

You might also like