Web API
Web API
ASP.NET Web API is a framework provided by 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.
Client and Server Separation: Server and Clients are clearly isolated in the RESTful
services.
Stateless: REST Architecture is based on the HTTP Protocol and 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
Attribute Routing
CORS (Cross-Origin Resource Sharing)
OWIN (Open Web Interface for .NET) self-hosting
IHttpActionResult
Web API OData etc.
Content-Type
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.
Yes, we can still develop RESTful services with WCF. However, there are two
main reasons that prompt users to use Web API instead of RESTful services.
It's a not at all true that ASP.NET Web API has replaced WCF. In fact, it is
another way of building non-SOAP based services, i.e., plain XML or JSON
string.
OData
Filters
Content Negotiation
Self-Hosting
Routing
Model Bindings
9) Web API uses which of the following open-source library for JSON
serialization?
10) By default, Web API sends HTTP response with which of the
following status code for all uncaught exception?
The biggest disadvantage of this approach is that you cannot directly return
an error code like 404 error.
12) How do you construct HtmlResponseMessage?
MaxAge = TimeSpan.FromMinutes(20)
};
return response;
Routes.MapHttpRoute(
Name: "ExampleWebAPIRoute",
routeTemplate: “api/{controller}/{id}
REST is used to make fewer data transfers between client and server which
make it an ideal for using it in mobile apps. Web API also supports HTTP
protocol. Therefore, it reintroduces the traditional way of the HTTP verbs for
communication.
16) How can we use Web API with ASP.NET Web Form?
18) Can you use Web API with ASP.NET Web Form?
Yes, It is possible to use Web API with ASP.Net web form. As it is bundled
with ASP.NET MVC framework. However, it can be used with ASP.NET Web
Form.
19) How Can assign alias name for ASP.NET Web API Action?
We can give alias name for Web API action same as in case of ASP.NET
MVC by using "ActionName" attribute as follows:
[HttpPost]
[ActionName("SaveStudentInfo")]
TestApi is a utility library of APIs. Using this library tester developer can create
testing tools and automated tests for a .NET application using data-structure
and algorithms.
[NotImplExceptionFilter]
23) How you can return View from ASP.NET Web API method?
No, we can't return a view from ASP.NET Web API Method. Web API creates
HTTP services that render raw data. However, it's also possible in ASP.NET
MVC application.
GlobalConfiguration.Configuration.Filters.Add(new
MyTestCustomerStore.NotImplExceptionFilterAttribute());
25) Explain what is REST and RESTFUL?
Config.Routes.MapHttpRoute(
);
Several classes are available in Web API to handle errors. They are HttpError,
Exception Filters, HttpResponseException, and Registering Exception Filters.
28) What New Features comes with ASP.NET Web API 2.0?
The latest features of ASP.NET Web API framework v2.0 are as follows:
Attribute Routing
Cross-Origin Resource Sharing
External Authentication
Open Web Interface NET
HttpActionResult
Web API OData
29) How can you restrict access methods to specific HTTP verbs in Web
API?
[HttpPost]
//logic
30) How can you pass multiple complex types in Web API?
paramList.Add(c);
paramList.Add(p);
32) Name the tools or API for developing or testing web api?
Testing tools for web services for REST APIs include:
1. Jersey API
2. CFX
3. Axis
4. Restlet
We can perform a Unit test using Web API tools like Fiddler.
Fiddler –Compose Tab -> Enter Request Headers -> Enter the Request Body
and execute
35) How can we restrict access to methods with specific HTTP verbs in
Web API?
Attribute programming is widely used for this functionality. Web API also
allows restricting access of calling methods with the help of specific HTTP
verbs. It is also possible to define HTTP verbs as attribute over method.
[NotImplExceptionFilter]
{
//write the code
38) Tell me the code snippet to show how we can return 404 errors from
HttpError?
[NotImplExceptionFilter]
43) By default, Web API sends HTTP response with which of the
following status code for all uncaught exception?
In WEB API HttpError used to throw the error info in the response body.
“CreateErrorResponse” method is can also use along with this, which is an
extension method defined in “HttpRequestMessageExtension.”
GlobalConfiguration.Configuration.Filters.Add (new
MyTestCustomerStore.NotImplExceptionFilterAttribute());
Several classes are available in Web API to handle errors. They are HttpError,
HttpResponseException, Exception Filters, Registering Exception Filters.
WCF services use the SOAP protocol while HTTP never use SOAP protocol.
That’s why WebAPI services are lightweight since SOAP is not used. It also
reduces the data which is transferred to resume service. Moreover, it never
needs too much configuration. Therefore, the client can interact with the
service by using the HTTP verbs.
WebAPI can be consumed by any client which supports HTTP verbs such as
GET, PUT, DELETE, POST. As WebAPI services don’t need any
configuration, they are very easy to consume by any client. Infract, even
portable devices like Mobile devices can easily consume WebAPI which is
certainly the biggest advantages of this technology.
50) How can we make sure that Web API returns JSON data only?
To make Web API serialize the returning object to JSON format and returns
JSON data only. For that you should add the following code in
WebApiConfig.cs class in any MVC Web API Project:
//JsonFormatter
//MediaTypeHeaderValue
Config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new
MediaTypeHeaderValue("application/json"));
//JsonFormatter
//MediaTypeHeaderValue
Config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new
MediaTypeHeaderValue("application/json"))
ASP.NET Web API is a framework that makes it easy to build HTTP
services that reach a broad range of clients, including browsers and
mobile devices. ASP.NET Web API is an ideal platform for building
RESTful applications on the .NET Core.
Using ASP.NET Web API, we can create non-SOAP based services like plain XML or JSON strings,
etc. with many other advantages including:
It works the HTTP way using standard HTTP verbs like GET, POST, PUT, DELETE, etc. for all
CRUD operations
Complete support for routing
Response generated in JSON or XML format using MediaTypeFormatter
It has the ability to be hosted in IIS as well as self-host outside of IIS
Supports Model binding and Validation
Support for OData
Q3: What is the difference between ApiController and Controller?
Answer
Consider:
Or
Q4:
Which status code used for all uncaught exceptions by
default?
Answer
By default, most exceptions are translated into an HTTP response with status code 500, Internal
Server Error.
Consider:
[Route("CheckId/{id}")]
[HttpGet]
public IHttpActionResult CheckId(int id)
{
if(id > 100)
{
throw new ArgumentOutOfRangeException();
}
return Ok(id);
}
For more control over the response, you can also construct the entire response message and
include it with the HttpResponseException:
The purpose of Web API framework is to generate HTTP services that reach more clients by
generating data in raw format, for example, plain XML or JSON string. So, ASP.NET Web
API creates simple HTTP services that renders raw data.
On the other hand, ASP.NET MVC framework is used to develop web applications that
generate Views (HTML) as well as data. ASP.NET MVC facilitates in rendering HTML easy.
Config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{Controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
So, any incoming request is matched against already defined routeTemplate and further routed to
matched controller action. But it’s really hard to support certain URI patterns using conventional
routing approach like nested routes on same controller. For example, authors have
books or customers have orders, students have courses etc.
Such patterns can be defined using attribute routing i.e. adding an attribute to controller action as
follows:
[Route("books/{bookId}/authors")]
public IEnumerable<Author> GetAuthorsByBook(int bookId) { ..... }
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.
REST is a stateless client-server architecture where web services are resources and can be
identified by their URIs. Client applications can use HTTP GET/POST methods to invoke Restful
web services. REST doesn’t specify any specific protocol to use, but in almost all cases it’s used
over HTTP/HTTPS.
When compared to SOAP web services, these are lightweight and doesn’t follow any standard. We
can use XML, JSON, text or any other type of data for request and response.
Answer
Some key characteristics of REST includes
REST is stateless, therefore the SERVER has no state (or session data)
With a well-applied REST API, the server could be restarted between two calls as every data
is passed to the server
Web service mostly uses POST method to make operations, whereas REST uses GET to
access resources
REST
a type,
relationship with other resources and
methods that operate on it.
their URI,
HTTP methods they support and
request/response data type and format of data.
<protocol>://<service-name>/<ResourceType>/<ResourceID>
GET: It requests a resource at the request URL. It should not contain a request body as it will
be discarded. Maybe it can be cached locally or on the server.
POST: It submits information to the service for processing; it should typically return the
modified or new resource
PUT: At the request URL it update the resource
DELETE: At the request URL it removes the resource
OPTIONS: It indicates which techniques are supported
HEAD: About the request URL it returns meta information
POST sends data to a particular URI and expects the resource at that URI to deal with the request.
The web server at this point can decide what to do with the data in the context of specified resource
PUT is idempotent meaning, invoking it any number of times will not have an impact on resources.
However, POST is not idempotent, meaning if you invoke POST multiple times it keeps creating
more resources
Since there is no contract defined between service and client, it has to be communicated
through other means such as documentation or emails.
Since it works on HTTP, there can’t be asynchronous calls.
Sessions can’t be maintained.
Q11: What are the best practices to create a standard URI for a web
service?
Answer
Following are important points to be considered while designing a URI:
Use Plural Noun − Use plural noun to define resources. For example, we've used users to
identify users as a resource.
Avoid using spaces − Use underscore(_) or hyphen(-) when using a long resource name,
for example, use authorized_users instead of authorized%20users.
Use lowercase letters − Although URI is case-insensitive, it is good practice to keep url in
lower case letters only.
Maintain Backward Compatibility − As Web Service is a public service, a URI once made
public should always be available. In case, URI gets updated, redirect the older URI to new
URI using HTTP Status code, 300.
Use HTTP Verb − Always use HTTP Verb like GET, PUT, and DELETE to do the operations
on the resource. It is not good to use operations names in URI.
Understandability − Both Server and Client should be able to understand and utilize the
representation format of the resource.
Linkablity − A resource can have a linkage to another resource, a format should be able to
handles such situations.
Web services need to get extra information in each request and then interpret to get the
client's state in case client interactions are to be taken care of.
Q14: What are the primary security issues of web service?
Answer
To ensure reliable transactions and secure confidential information, web services requires very high
level of security which can be only achieved through Entrust Secure Transaction Platform. Security
issues for web services are broadly divided into three sections as described below
1) Confidentiality: A single web service can have multiple applications and their service path
contains a potential weak link at its nodes. Whenever messages or say XML requests are sent by
the client along with the service path to the server, they must be encrypted. Thus, maintaining the
confidentiality of the communication is a must.
2) Authentication: Authentication is basically performed to verify the identity of the users as well as
ensuring that the user using the web service has the right to use or not? Authentication is also done
to track user’s activity. There are several options that can be considered for this purpose
3) Network Security: This is a serious issue which requires tools to filter web service traffic.
Monolithic Architecture is similar to a big container wherein all the software components of
an application are assembled together and tightly packaged.
A Service-Oriented Architecture is a collection of services which communicate with each
other. The communication can involve either simple data passing or it could involve two or
more services coordinating some activity.
Microservice Architecture is an architectural style that structures an application as a
collection of small autonomous services, modeled around a business domain.
Answer
GraphQL and microservices are a perfect fit, because GraphQL hides the fact that you have a
microservice architecture from the clients. From a backend perspective, you want to split everything
into microservices, but from a frontend perspective, you would like all your data to come from a
single API. Using GraphQL is the best way I know of that lets you do both. It lets you split up your
backend into microservices, while still providing a single API to all your application, and allowing
joins across data from different services.
1. What is REST?
Representational state transfer(REST) is an abstraction of architecture of world wide
web. REST is an architectural style to design networked application.REST makes
communication between remote computers easy by using the simple HTTP protocol which
support for CRUD (Create, Read, Update, and Delete) operations on the server.
ex: CsharpStar.com/posts
o The base uri can be qualified with an identifier specifying an individual resource
ex: CsharpStar.com/posts/1053
o RESTful services are hierarchical, resources offered by one service can contain
more service
o REST uses various representations to represent a resource where text, JSON, XML.
XML and JSON are the most popular representations of resources
1. GET retrieves it
2. DELETE destroys it
3. PUT replaces it or create if doesnot exists
Disadvantages:
o Web services need to get extra information in each request and then interpret to
get the client’s state in case client interactions are to be taken care of.
SOAP Web Services: Runs on SOAP protocol and uses XML technology for sending data.
Restful Web Services: It’s an architectural style and runs on HTTP/HTTPS protocol almost
all the time. REST is a stateless client-server architecture where web services are resources
and can be identified by their URIs. Client applications can use HTTP GET/POST methods
to invoke Restful web services.
Q4:
What is purpose of a URI in REST based webservices?
Answer
URI stands for Uniform Resource Identifier. Each resource in REST architecture is identified by its
URI. Purpose of an URI is to locate a resource(s) on the server hosting the web service.
<protocol>://<service-name>/<ResourceType>/<ResourceID>
Q5:
Why is the Root Certificate important?
Answer
A Root SSL certificate is a certificate issued by a trusted certificate authority (CA).
In the SSL ecosystem, anyone can generate a signing key and sign a new certificate with that
signature. However, that certificate is not considered valid unless it has been directly or indirectly
signed by a trusted CA.
A trusted certificate authority is an entity that has been entitled to verify that someone is
effectively who it declares to be. In order for this model to work, all the participants on the game
must agree on a set of CA which they trust. All operating systems and most of web browsers ship
with a set of trusted CAs.
Q7:
How would you choose between SOAP and REST web
services?
Answer
Web Services work on client-server model and when it comes to choose between SOAP and REST,
it all depends on project requirements. Let’s look at some of the conditions affecting our choice:
Do you know your web service clients beforehand? If Yes, then you can define a contract
before implementation and SOAP seems better choice. But if you don’t then REST seems
better choice because you can provide sample request/response and test cases easily for
client applications to use later on.
How much time you have? For quick implementation REST is the best choice. You can
create web service easily, test it through browser/curl and get ready for your clients. What
kind of data format are supported? If only XML then you can go with SOAP but if you think
about supporting JSON also in future then go with REST.
Q8:
Mention what is the difference between RPC or document
style web services? How you determine to which one to
choose?
Answer
In document style web services, we can transport an XML message as part of SOAP request which
is not possible in RPC style web service. Document style web service is most appropriate in some
application where XML message behaves as document and content of that document can alter and
intention of web service does not rely on the content of XML message
Q9:
What are different ways to test web services?
Answer
SOAP web services can be tested programmatically by generating client stubs from WSDL
or through software such as Soap UI.
REST web services can be tested easily with program, curl commands and through browser
extensions. Resources supporting GET method can be tested with browser itself, without any
program.
Q11:
What are main differences between Microservices and
Monolithic Architecture?
Answer
Microservices
Monolithic Architecture
Q17:
What is the difference between encryption, encoding, and
hashing?
Answer
Encryption, encoding and hashing are techniques used for converting the format of data.
Encryption is used for changing plain text into cipher text so that only authorized entities
can understand it. Encryption deals with keys which are used to encrypt and decrypt the
data. These keys are used to transform a simple text into a cypher text and the vice versa.
Encoding is used for changing the data into a special format which makes it usable by
external processes. Unlike encryption, the intention of encoding is not related to security.
The message is encoded by using an algorithm or scheme.
In hashing, the data is converted to a message digest or hash, which is usually a number
generated from a string of text. Hashing is not reversible as encryption and encoding. The
data is converted to a message digest or hash, which is usually a number generated from a
string of text. These digests are important as one can easily match the hash of sent and
received messages to ensure that both are the same and no tempering is done with the
data.
ASP.NET Web API is a framework provided by the Microsoft open source technology for building
and consuming HTTP based services on top of .NET Framework. The advantage of Web API is that
it can be consumed by a broader range of clients including web browser and mobile applications, IoT
etc. ASP.NET Web API provides an ideal platform for building RESTful applications on the .NET
HTTP (Hypertext Transfer Protocol) is an application level protocol that is used to deliver data such
as html files, image files, query results, etc. on the World Wide Web. HTTP is a stateless protocol,
meaning that after one cycle of request and response the server forgets everything about the cycle,
and it considers another request from the same client as a new request from a new client.
ASP.NET framework ships out with the .NET framework and is Open Source
Web API is a lightweight architecture and is good for the devices which have limited
bandwidth
We can expose services to a variety of clients easily like browsers or mobile devices, etc.
Web API increases TDD (Test Data Driven) approach in the development of RESTful
services.
URI is a string of characters used to identify a resource on the internet either by location or by name,
“Test Person” who lives in “403, Test City, World”. We can find that person by address or by name or
by both.
URI is used to send requests to the server. This can be achieved with the help of both URN and
URL. Using URN is inefficient, as there can be many resources with the same name. So the most
widely used method is URL. URL consists of two required components The Protocol & The Domain.
http://www.testname.net/asp-net-webapi
Here the red colored part is the protocol and the black colored part is the domain, other parts are
There are various types of HTTP methods and they can be used according to the requirements.
GET – The GET method is used to get or retrieve the information from the respective server
HEAD – This is the same as GET, but transfers the status line and header section only.
PUT – It is used for update and it replaces all current resources with the uploaded content.
TRACE – Performs a message loop-back test along the path to the target resource.
HTTP Status Codes are the 3 digit integers which contain in server response. There is a meaning for
each number. Response Header of each API response contains the HTTP Status Code. The first
digit of the Status-Code defines the class of response. HTTP Status Codes are grouped into five
1xx: Informational-It means the request has been received and the process is continuing.
2xx: Success-It means the action was successfully received, understood, and accepted.
3xx: Redirection-It means further action must be taken in order to complete the request.
4xx: Client Error-It means the request contains incorrect syntax or cannot be fulfilled
5xx: Server Error-It means the server failed to fulfill an apparently valid request.
Some of the commonly seen HTTP Status Codes are: 200 (Request is Ok), 201 (Created), 202
(Accepted), 204 (No Content), 301 (Moved Permanently), 400 (Bad Request), 401 (Unauthorized),
403 (Forbidden), 404 (Not Found), 500 (Internal Server Error), 502 (Bad Gateway), 503 (Service
Unavailable) etc.
What is HTTP Content
HTTP header fields are components of the header section of request or response messages in the
Hypertext Transfer Protocol. It defines the operating parameters of an HTTP transaction. There are
For example, HTTP request to fetch aspnetwebapi.htm page from the web server running on
developmenthelp.net.
Media Type is a file identification mechanism on the MIME encoding system, formerly “MIME type”.
The Internet media type has become the de facto standard for identifying content on the Internet.
For example, consider an instance of receiving an email from a server with an attachment, the
server embeds the media type of the attachment in the message header. So, the browser can
It is difficult to say which one is better between Web API and WCF Rest service. Both the
technologies have their own significant in the context of development, hosting and consuming the
service.Although both WCF REST and ASP.NET Web API follow the REST architecture, these have
WCF Rest
Microsoft has introduced “WebHttpBinding” that needs to be enabled for creating WCF
RESTful Services.
HTTP Methods are mapped to attributes. So, for each method there must be attributes like –
Web API
Unlike WCF Rest we can use the full features of HTTP in Web API.
“WebHttpBinding” to be used for creating WCF RestFul services. WebAPI Supports full features of HTTP.
HTTP Methods are mapped to attributes for example It possible to host Web API in IIS as well as
GET for WebGet and POST for WebInvoke. in an application
XML stands for eXtensible Markup Language. It is a markup language like HTML and is designed to
store and transport data. XML doesn’t do anything, but it can store data in a specific format.
JSON stands for JavaScript Object Notation and is also used to store and transport data. JSON is
often used when data is sent from a server to a web page. JSON is "self-describing" and easy to
Using ASP.NET Web API comes with a number of advantages, the core advantages being:
It works the HTTP way using standard HTTP verbs like GET, POST, PUT, DELETE, etc. for
Filters
Content Negotiation
Compare WCF vs ASP.NET Web API and state the differences with advantages and
disadvantages?
using a variety of transport protocols like HTTP, TCP, NamedPipes or MSMQ, etc. WCF i.e.
Windows Communication Foundation is a framework used for building Service Oriented applications
(SOA) and supports multiple transport protocols like HTTP, TCP, MSMQ, etc. WCF ships out with
the .NET Framework. WCF service is good for Message Queue, duplex communication, one-way
ASP.NET API is a framework for building non-SOAP based services over HTTP only. 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 platform for building RESTful applications. It is limited to HTTP
based services. ASP.NET framework ships out with the .NET framework and is Open Source. One
major advantage of Web API is that it is the best fit with MVC pattern. Web API supports any media
WCF WebAPI
Multiple protocol support (like HTTP, TCP, Named Pipes and Supports only HTTP
Protocol
more) protocol
Follows REST
Principles Follows WS-* specification
Principles
needed to run.
While ASP.Net
It’s a misconception that ASP.NET Web API has replaced WCF. It’s another way of building non-
SOAP based services, for example, plain XML or JSON string etc.
Yes, it has some added advantages like utilizing full features of HTTP and reaching more clients
1. If we intended to use transport other than HTTP e.g. TCP, UDP or Named Pipes.
1. SOAP stands for Simple Object Access Protocol whereas REST stands for Representational
State Transfer.
2. The SOAP is an XML based protocol whereas REST is not a protocol but it is an
completely stateless.
4. SOAP enforces message format as XML whereas REST does not enforce message format
as XML or JSON.
5. The SOAP message consists of an envelope which includes SOAP headers and body to
store the actual information we want to send whereas REST uses the HTTP build-in headers
(with a variety of media-types) to store the information and uses the HTTP GET, POST, PUT
6. SOAP uses interfaces and named operations to expose the service, whereas to expose
resources (service) REST uses URI and methods like (GET, PUT, POST, DELETE).
First Version of ASP.NET Web API is introduced in .NET Framework 4. After that, all the later
versions of the .NET Framework support the ASP.NET Web API.
REST or Representational State Transfer is an architectural style for designing applications. Instead
of using complex mechanisms like CORBA, RPC or SOAP for communication, it dictates that HTTP
should be used.
RESTFUL: It is term written by applying REST architectural concepts and is called RESTful
services. It focuses on system resources and how the state of the resource should be transported
It completely depends upon the requirement. Choose ASP.NET Web API if you want HTTP based
services only, as Web API is a lightweight architecture and is good for the devices which have
limited bandwidth. We can also create the REST services with WCF, but that requires a lot of
configuration. In case you want a service that should support multiple transport protocols like HTTP,
UDP, TCP, etc. then WCF will be the better option.
WCF
WCF supports a variety of transport protocols like – HTTP, TCP, Named Pipes or MSMQ
etc.
WCF service is good for Message Queue, duplex communication, one-way messaging.
Web API
It supports most of the MVC features which keep Web API over WCF.
The purpose of Web API framework is to generate HTTP services that reach more clients by
generating data in raw format, for example, plain XML or JSON string. So, ASP.NET Web
In the ASP.NET Web API request is mapped to Action based on the Action Verbs.
MVC
ASP.NET MVC is used to create a web application which returns both data as well as View
(HTML) whereas Web API is used to create HTTP based Services which only returns data
MVC is used to create a web app, in which we can build web pages.
REST stands for Representational State Transfer. This term was coined by Roy Fielding in 2000.
RESTful is an Architectural style for creating loosely coupled applications over HTTP. In order to
make API to be RESTful, it must adhere to the around 6 constraints that are mentioned below:
Client and Server Separation: Server and Clients are clearly isolated in the RESTful services.
This constraint specifies that a Client sends a request to the server and the server sends a response
back to the client. This separation of concerns supports the independent development of both client-
side and server-side logic. That means client application and server application should be developed
separately without any dependency on each other. A client should only know resource URIs and
that’s all. Severs and clients may also be replaced and developed independently as long as the
Stateless: REST Architecture is based on the HTTP Protocol and the server response can be
cached by the clients, but no client context would be stored on the server.
The stateless constraint specifies that the communication between the client and the server must be
stateless between requests. This means that we should not be storing anything on the server related
to the client. The request from the client should contain all the necessary information for the server
to process that request. This ensures that each request can be treated independently by the server.
Uniform Interface: Allows a limited set of operations defined using the HTTP Verbs. For eg:
The uniform interface constraint defines an interface between the client and the server. To
understand the uniform interface constraint, we need to understand what a resource is and the
HTTP verbs – GET, PUT, POST and DELETE. In the context of a REST API, resources typically
represent data entities. The product, Employee, Customer, etc. are all resources. The HTTP verbs
(GET, PUT, POST, and DELETE) that are sent with each request tell the API what to do with the
Cacheable: RESTful architecture allows the response to be cached or not. Caching improves
Some data provided by the server like the list of products, or list of departments in a company does
not change that often. This constraint lets the client know how long this data holds good, so that the
client does not have to come back to the server for that data over and over again.
Code-On-Demand:is any technology that sends executable software code from a server to a
client upon request from the client. The program code lies inactive on a web server until a
client requests a web page that contains a link to the code using the client's web browser.
Upon this request, the web page and the program are transported to the user's machine
using HTTP. When the page is displayed, the code is started in the browser and executes
locally, inside the user's computer until it is stopped (e.g., by the user leaving the web page).
Layered System:REST allows us to use a layered system architecture where we deploy the
APIs in server A, and store data on server B and authenticate requests in server C. For
example, a client cannot ordinarily tell whether it is connected directly to the server or to an
We can unit test the Web API using the Fiddler tool. Below are the settings to be done in Fiddler –
Compose Tab -> Enter Request Headers -> Enter the Request Body and execute.
Most of the people give the wrong answer for this question. The right answer is No, we can’t. Web
API does not return View but returns the data. As we discussed in an earlier interview question
about the difference between ASP.NET MVC and Web API, ASP.NET Web API creates HTTP
services that render raw data. Although, it’s quite possible in ASP.NET MVC application, the
APIController is meant for returning the data. So, if you need to return a view from the controller
class, then make sure to use or inherit the Controller class.