What is RESTful about ASP.NET MVC?

REST has been such a popular buzzword over the last couple of years (or so), and when ASP.NET MVC rolled out, everyone connected REST with ASP.NET MVC. I also fell in noise and due to a lack of my knowledge, my understanding of REST was simple:

REST = SEO / User Friendly URLs

But it is much more. And the more I learn about REST, the less I associate ASP.NET MVC with it. This, of course, is much closer to REST than to WebForms. So the truth is actually quite the opposite:

REST ≠ SEO / User Friendly URLs

And if your default route, defined as controller/action/id , is definitely not RESTful.

Let me explain my problem with this understanding.

If ASP.NET MVC was RESTful, we would not have a default route defined as:

 controller/action/id 

but rather

 resources/id /* that would have to use HTTP methods GET/PUT/POST/DELETE */ 

So, instead of having (also providing an HTTP method with a request):

 /product/index/1 /* GET */ /product/create /* POST */ /product/delete/1 /* POST */ /product/update/1 /* POST */ 

it should be (an HTTP method is also provided here)

 /products/1 /* GET */ /products /* POST */ /products/1 /* DELETE */ /products/1 /* PUT */ 

Now it will be RESTful. Well, that is really possible. And if you do it completely RESTful, it would also mean that you should use Ajax , because the PUT and DELETE methods cannot be executed using browser-only queries (this is not entirely true 1 ). Thus, modern Ajax applications can be completely RESTful.

Ajax is a client technology and actually has nothing to do with ASP.NET MVC. The fact is that ASP.NET MVC can be run as a fully RESTful application. The means of achieving it (Ajax) does not matter. (thanks to Darin Dimitrov)

Main question

Why do we see ASP.NET MVC as a RESTful structure, especially related to its URL routing? Why didn't they set a default URL route to ensure RESTfulness? I am not looking for argumentative answers, but those that actually answer the question - how did this attitude come to life ... Perhaps I am still not wise enough and still perceive this as a lack of my knowledge of both.

1 Updated Information

In fact, you do not need to use Ajax to fully implement the RESTful architecture. Asp.net MVC supports (starting from version 2) the HTTP overriding method, that is, you can issue PUT or DELETE methods using browser forms. All you have to do is add an extra hidden field, for example:

 <input type="hidden" name="X-HTTP-Method-Override" value="DELETE" /> 

The Asp.net MVC structure will be able to understand a POST request such as a DELETE request, and the HttpDeleteAttribute action selector will also understand it as a delete request. HTTP method overriding FTW!

+49
rest asp.net-mvc routing
Sep 16 '10 at 20:59
source share
7 answers

Nothing prevents you from using routes such as resource/id using the HTTP methods GET / PUT / POST / DELETE in ASP.NET MVC. This is not the default route setup, but you can do it.

EDIT (MLaritz - adding Darin's comment): ASP.NET MVC is a server-side technology that allows you to identify RESTful URLs. How they are consumed does not matter. You asked why ASP.NET MVC is considered RESTFul technology, and the answer is that you can easily expose RESTFul URLs for consumption, it's that simple.

+26
Sep 16 '10 at 21:07
source share

I think a lot of noise was related to how the un-RESTful .NET web stack was before MVC and how much easier MVC made it to create RESTful applications on the .NET platform than any features of RESTful ASP.NET MVC has.

+15
Sep 16 '10 at 21:15
source share

There is no URI style that makes an API unforgettable.

You asked: "Why do we consider ASP.NET MVC as a RESTful structure, especially related to its routing of URLs?"

Because REST misunderstands that this is about URLs, not about resources, a standard interface, and hypermedia .

+11
Sep 19 '10 at 5:07
source share

This link may enlighten you in your quest ... In short, you may have URLs that you describe - at least with MVC 2.

+5
Sep 16 '10 at 21:06
source share

I just thought to contribute to the REST discussion about using PUT and DELETE.

In general, in REST and other RESTful systems, the problem of PUT and DELETE is not solved by creating URLs such as resource/create or resource/delete . Rather, the verb is tunneled through POST:

  • Passing hidden input in HTML format, for example _method .
  • Using JavaScript to execute PUT or DELETE
  • To overcome some firewalls, you may need to use the HTTP header X-HTTP-Method-Override .

This is a general solution to the problem of HTTP methods.

I was not informed about ASP.Net to say why they did not, but a URL like /product/delete/1 does not provide a RESTful resource.

Change A little clarification on what REST is seems to be necessary. From the mouth of a horse :

The REST API should not contain any changes to the communication protocols, except for filling in or correcting the details of the incomplete bits of standard protocols, such as the HTTP PATCH method or the link header field. Workarounds for broken implementations ( such as those browsers that are dumb enough to assume HTML defines an HTTP method method ) must be defined separately or, at least in applications, with the expectation that the workaround will end up will be obsolete. [Failure here means that resource interfaces are object-oriented, not universal.]

The emphasis is mine. REST is not defined as using four HTTP methods. It is not even defined as using HTTP. He needs a communication protocol with the ability to track hyperlinks. And he uses this protocol, with the addition of suitable definitions without violating the protocol.

In the case of HTTP, workarounds for browsers that do not implement PUT and DELETE are explicitly allowed. The Rails method in step 1 explicitly does this.

+3
Sep 17 '10 at 12:21
source share

This question is slightly outdated, and the answer right now (2014-08) will be as follows: ASP.NET MVC allows for RESTful URL schemes, but is not designed to have this default value. Instead, the core of success with ASP.NET MVC is the more traditional Controller + Action type for MVC.

Currently, ASP.NET for writing RESTful services will be the ASP.NET Web API. This makes it easy to create a RESTful URL scheme using method naming conventions that match HTTP verbs.

Please note that this answer will be deprecated after ASP.NET vNext is currently being called, in which the web APIs and MVC are included in one.

+2
Aug 22 '14 at
source share

Project Manager: "Let the new project be fully developed by RESTful !!!"

Other programmers shout: "YAyyyyyy !!!"

  • A few weeks later at the development stage: "Sir, we must allow the client to be able to update several rows at the same time, so we need to make a workaround"

  • "Sir, I only need to get the last bill."

  • "Sir, I have to pass the numbers and paging size!"

bummer. why don't we go back to XML RPC

+1
Oct 10 '13 at 9:43 on
source share



All Articles