0% found this document useful (0 votes)
21 views11 pages

Unit 3

The document provides an overview of Web API, detailing its introduction, importance, and various uses in web development. It contrasts Web API with WCF, explains the differences between REST API and RESTful API, and outlines the advantages of using REST in Web API. Additionally, it covers MVC architecture, its components, and features, as well as routing in ASP.NET Web API.

Uploaded by

admissions.axiom
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views11 pages

Unit 3

The document provides an overview of Web API, detailing its introduction, importance, and various uses in web development. It contrasts Web API with WCF, explains the differences between REST API and RESTful API, and outlines the advantages of using REST in Web API. Additionally, it covers MVC architecture, its components, and features, as well as routing in ASP.NET Web API.

Uploaded by

admissions.axiom
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

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.

Why is the Web API important?

Web API is generally considered as a service that basically provides us information or


data from the server. It is very important because of the following reasons:

• 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, increases interest
in the company’s product and services, increases website traffic.
What is Web API and why we use it ?

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.

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.NET MVC and different types of web applications such as
ASP.NET WebForms.
• If one wants to create resource-oriented 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 in Web API?

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.

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

Web API WCF


It is used to develop both SOAP-based It is used to deploy only SOAP-based
services and RESTful services. services.
It supports various MVC features such as
It does not support any MVC features.
routing, model binding, etc.
It supports various protocols such as
It only supports HTTP protocol.
HTTP, UDP, custom transport.
It is considered best for developing RESTFUL
It supports only limited RESTFUL services.
services.
It is good when one wants to expose an It is good for creating services that uses
expensive range of clients such as iPhones, expedite transport channels such as TCP,
browsers, mobile phones, tablets, etc. UDP, Named pipes, etc.
It offers TEXT, Binary encoding support,
It offers support for UTF-8 encoding format. MTOM (Message Transmission
Optimization Mechanism), etc.
5. Why to choose Web API over WCF?

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

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

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

REST API RESTful API


REST is an architectural pattern used
RESTful API is used to implement that pattern.
for creating web services.
The data format of REST is based on The data format of RESTful is based on JSON,
HTTP. HTTP, and Text.
Working of URL is based on request
Working of RESTful is based on REST applications.
and response.
It is more user-friendly and highly
adaptable to all business enterprises It is too flexible.
and IT.
It is required to develop APIs that It simply follows REST infrastructure that provides
allow interaction among clients and interoperability among different systems on the
servers. whole network.
What are the advantages of using Rest in Web API?

REST is very important and beneficial in Web API because of the following reasons:

• It allows less data transfer between client and 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.
• It uses simple HTTP calls for inter-machine communication rather than using more
complex options like CORBA, COM+, SOAP, or RPC.

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 Filter: It handles authentication and authenticates HTTP requests. It


also helps to authenticate user detail. It checks the identity of the user.
• Authorization Filter: It handles authorization. It runs before controller action. 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.
• AuthorizeAttribute 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 after controller action executes. It is simply a way
to add extra functionality to Web API 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 filter or controller level filter. It is simply used to modify the behavior of other
filters for individual action methods.
What is MVC? Write difference between MVC and Web API?

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.

MVC Web API


It can be used to build Web applications that It is used to build HTTP services that
reply as both data and views. reply only as data.
It returns data in JSON format by using It returns data in different formats
JSONResult. such as JSON, XML, etc.
It does not support content
It supports content negotiation, self-hosting.
negotiation, self-hosting.
It is very helpful in creating REST-full
It is not able to build REST-full services.
services.
It returns a view (HTML). It returns REST responses.
What is the difference 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.GetTweets();
}
}

Controller: It is used to provide normal views.

public class TweetsController : Controller


{
// GET: /Tweets/ [HttpGet] public ActionResult Index()
{
return Json(Twitter.GetTweets(), JsonRequestBehavior.AllowGet);
}
}

What is ASP.NET Web API 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.

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.
Explain MVC flow diagram.

MVC Flow Diagram

Flow Steps
Step 1 − The client browser sends request to the MVC Application.
Step 2 − Global.ascx receives this request and performs routing based on the URL of
the incoming request using the RouteTable, RouteData, UrlRoutingModule and
MvcRouteHandler objects.
Step 3 − This routing operation calls the appropriate controller and executes it using the
IControllerFactory object and MvcHandler object's Execute method.
Step 4 − The Controller processes the data using Model and invokes the appropriate
method using ControllerActionInvoker object
Step 5 − The processed Model is then passed to the View, which in turn renders the
final output.

What is MVC?List and explain different components of it.

The Model-View-Controller (MVC) is an architectural pattern that separates an


application into three main logical components: the model, the view, and the
controller. Each of these components are built to handle specific development
aspects of an application. MVC is one of the most frequently used industry-
standard web development framework to create scalable and extensible
projects.

MVC Components
Following are the components of MVC −

Model
The Model component corresponds to all the data-related logic that the user works with.
This can represent either the data that is being transferred between the View and
Controller components or any other business logic-related data. For example, a
Customer object will retrieve the customer information from the database, manipulate it
and update it data back to the database or use it to render data.
View
The View component is used for all the UI logic of the application. For example, the
Customer view will include all the UI components such as text boxes, dropdowns, etc.
that the final user interacts with.
Controller
Controllers act as an interface between Model and View components to process all the
business logic and incoming requests, manipulate data using the Model component and
interact with the Views to render the final output. For example, the Customer controller
will handle all the interactions and inputs from the Customer View and update the
database using the Customer Model. The same controller will be used to view the
Customer data.

ASP.NET MVC Features


ASP.NET MVC provides the following features −
• Ideal for developing complex but lightweight applications.
• Provides an extensible and pluggable framework, which can be easily replaced
and customized. For example, if you do not wish to use the in-built Razor or
ASPX View Engine, then you can use any other third-party view engines or even
customize the existing ones.
• Utilizes the component-based design of the application by logically dividing it into
Model, View, and Controller components. This enables the developers to manage
the complexity of large-scale projects and work on individual components.
• MVC structure enhances the test-driven development and testability of the
application, since all the components can be designed interface-based and tested
using mock objects. Hence, ASP.NET MVC Framework is ideal for projects with
large team of web developers.
• Supports all the existing vast ASP.NET functionalities, such as Authorization and
Authentication, Master Pages, Data Binding, User Controls, Memberships,
ASP.NET Routing, etc.
• Does not use the concept of View State (which is present in ASP.NET). This
helps in building applications, which are lightweight and gives full control to the
developers.

You might also like