MVC and REST - REST architecture


MVC and  REST : REST architecture

<<Previous  Next>>
Model view controller
Page controller pattern
MVC design
REST architecture
MVC framework

ASP.NET 3.5 Application Architecture and Design

This excerpt from ASP.NET 3.5 Application Architecture and Design by Thiru Thangarathinam, is printed with permission from Packt Publishing, Copyright 2007.

REST: Representation State Transfer

REST: Representation State Transfer

REST means Representational State Transfer, an architectural pattern used to identify and fetch resources from networked systems such as the World Wide Web (WWW). The REST architecture was the foundation of World Wide Web. But the term itself came into being around the year 2000, and is quite a buzzword these days. The core principle of REST is to facilitate the sharing of resources via unique identifi ers, just as we use Uniform Resource Identifi ers (URIs) while accessing resources on the Web. In simple terms, REST specifi es how resources should be addressed, including URI formats, and protocols such as HTTP. The term resources include fi les such as ASPX pages, HTML fi les, images, videos, and so on.

In the default page controller based design in ASP.NET, we don't follow a strict REST-based architecture. If we use a pure REST-based architecture, then all of the information required to access a particular resource would be in the URI. This means that we don't need to check if a postback happened or not, because each request is unique in itself and will be treated differently (via unique URLs). Whereas in ASP. NET, we can use the postback technique to make the same requests using the same URLs and do different processing based on whether it is a postback or not. Many a times, in numerous projects, we come across the following coding style in ASP.NET code-behind fi les:


Here, on the postback (button click), we are redirecting the user to another resource (mypage.aspx), and this approach goes against the REST principle as we are delegating the responsibility to load a resource to another page based controller's postback event. This is not REST-like behavior. Now, we will see how MVC compliments the REST approach.


MVC is radically different from the default page controller based design in the ASP.NET framework as it implements a front controller based design. In our normal applications, we use a lot of postbacks and make use of ViewState, and the development is centered around web forms. For each functional aspect, we may have a single webform; for example, for adding customers, we might create something like AddCustomer.aspx, and for showing a list of customers, we might use CustomerList.aspx.

But in an MVC architecture, webforms lose their importance. We don't create webforms in the same way that we do in standard ASP.NET applications. In the MVC framework, we use URL routing, which means that all URLs have some specifi c format, and the URLs are used based on the settings in a config fi le. In a standard ASP.NET application, the URL is linked to a specifi c ASPX fi le, say http://localhost/CustomerList.aspx. In MVC, the URL routes are defi ned in a REST-like fashion: http://localhost/customer/list/.

So in MVC, ASPX pages are reduced to simply showing the view; they will not have any code in their code-behind classes. What needs to be shown on an ASPX page will be handled by the Controller classes. ASPX will just be a kind of view engine and nothing else. ASPX will not have control-level event handlers or any kind of logic in the code-behind. In the next section, we will see how the ASP.NET MVC framework makes our life easier in adopting an MVC based approach in our projects.

<<Previous  Next>>

Write your comment - Share Knowledge and Experience

Discussion Board
URL Routing in ASP.Net 3.5(IIS7)


I was reading your article and I would like to appreciate you for making it very simple and understandable. This article gives me a basic idea of URL Routing in ASP.Net 3.5(IIS7) and it helped me a lot. Thanks for sharing with us. Check out this link too its also having nice post with wonderful explanation on URL Routing in ASP.Net 3.5(IIS7), for more details check this....

Thank you very much!

Jeet Verma 01-10-2012 03:59 AM


More Related links 

ASP.NET State Management Interview questions with answers 
Define state management in ASP.NET. | Define Client-side state management and Server-side state management.
ASP.NET Globalization-Localization questions with answers
What is Globalization and Localization in ASP.NET? | What are the Globalization approaches possible in ASP.NET? | Implementing ASP.NET Globalization | Define Resource Files and Satellite Assemblies
.NET Code Security Interview questions with answers
What is code security? What are the types? | Define Principal object. | Define declarative and imperative security. | Define role-based security. | Explain code access security. | What is Code group? | Define the use of Caspol.exe.
.NET Debug & Trace Interview questions with answers 
What is break mode? What are the options to step through code? | Debug Vs Trace. | Define trace class. Define Listeners collection of Trace and Debug objects. | Define Trace Switches.
Visual Studio 2005 Improvements

Visual Studio 2005 is the best development tool for building data-driven web applications. As part of the Visual Studio 2005 suite of tools, Microsoft is introducing a new tool called Visual Web Developer (VWD) that is designed to work with the current and next generation of ASP.NET. VWD provides powerful new features for the web developer.................

ASP.NET 2.0 Administration and Management

One of the key goals of ASP.NET 2.0 is to ease the effort required to deploy, manage, and operate ASP.NET web sites. To this end, ASP.NET 2.0 features a new Configuration Management API that enables users to programmatically build programs or scripts that create, read, and update configuration files such as Web.config and machine.config.............


Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us | We are hiring