Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's so RESTful about ASP.NET MVC?
    primarykey
    data
    text
    <p>REST has been such a popular buzzword for the last couple of years (or so) and when ASP.NET MVC rolled out, everyone was relating REST with ASP.NET MVC. I also fell for the buzz and from the lack of my knowledge, my understanding of REST was simply just:</p> <h2>REST = SEO/User friendly URLs</h2> <p>But it's so much more. And the more I learn about REST the less I relate ASP.NET MVC with it. It is of course much closer to REST than WebForms. So the truth is actually quite the opposite:</p> <h2>REST ≠ SEO/User friendly URLs</h2> <p>And having your default route defined as <code>controller/action/id</code> is <strong>definitely</strong> not RESTful.</p> <p>Let me explain my problem with this comprehension.</p> <p>If ASP.NET MVC was RESTful, we wouldn't have default route defined as:</p> <pre><code>controller/action/id </code></pre> <p>but rather</p> <pre><code>resources/id /* that would have to use HTTP methods GET/PUT/POST/DELETE */ </code></pre> <p>So instead of having (also providing HTTP method with request path):</p> <pre><code>/product/index/1 /* GET */ /product/create /* POST */ /product/delete/1 /* POST */ /product/update/1 /* POST */ </code></pre> <p>it should be (HTTP method provided here as well)</p> <pre><code>/products/1 /* GET */ /products /* POST */ /products/1 /* DELETE */ /products/1 /* PUT */ </code></pre> <p><strong>Now that would be RESTful.</strong> The good thing is that this is actually possible. And if you'd make it fully RESTful it would also mean that you'd <strong>have to use Ajax</strong> because PUT and DELETE methods can not be done with browser-only requests (this is not completely true<sup>1</sup>). So modern Ajax applications can actually be completely RESTful.</p> <blockquote> <p>Ajax is client technology and doesn't really have anything to do with ASP.NET MVC. Fact is that ASP.NET MVC can be done as a fully RESTful application. The means of achieving it (Ajax) is not important. (thanks to Darin Dimitrov)</p> </blockquote> <h2>The main question</h2> <p><strong>Why do we consider ASP.NET MVC as a RESTful framework especially relating its URL routing to it?</strong> Why didn't they define default URL route to <em>enforce</em> RESTfulness? I'm not looking for argumentative answers but those that actually answer the question - how did this relation come into life... Maybe I'm still not wise enough and still take this as the lack of my knowledge about both.</p> <h2><sup>1</sup>Updated info</h2> <p>Actually you don't have to use Ajax to implement fully RESTful architecture. Asp.net MVC supports (since version 2) HTTP method overriding, meaning you can issue PUT or DELETE methods using browser forms. All you have to do is add an additional hidden field like:</p> <pre><code>&lt;input type="hidden" name="X-HTTP-Method-Override" value="DELETE" /&gt; </code></pre> <p>Asp.net MVC framework will be able to understand such POST request as a DELETE request and <code>HttpDeleteAttribute</code> action method selector will also understand it as a delete request. HTTP Method overriding FTW!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload