Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST Web Services using MVC, is it a good idea?

In .Net, I think about a web service as being a project type that you select from the menu, define your classes and methods then .Net does all this black magic under the hood to allow someone on the other side of the world to reference my web service and start coding using my classes and methods directly within their visual studio.

So having this preconceived notion, when looking at writing REST web services using MVC 3 (I know MVC 4 has a REST api baked in but am waiting for a full release) I'm wondering all the usual stuff like "is this a good idea", "will this stand up to heavy use" and "am I just writing toy web services that other developers will laugh at".

Now I think a lot of my anxiety is probably down to microsoft not having wrapped a big, overly complicated, bloated, shiny REST package around it yet. So I'm looking to have my anxiety relieved hopefully by people telling me yes MVC web services are perfectly good things to create.

Any help?

like image 240
David Avatar asked Mar 06 '12 12:03

David


People also ask

Should I use MVC API?

Web API can be used for generating HTTP services that replies data alone, but MVC would be suitable for developing web applications that replies as both, views and data. Web API looks at Accept Header of the request who returning the data in various formats, so it can return in various formats, like XML, JSON etc.

Can MVC be RESTful?

ASP.NET MVC is one such framework that provides an inherently RESTful model for building XHTML-based services.

What are the reasons for developing webservices using the Spring MVC framework?

In Spring MVC, a controller can handle the requests for all HTTP methods, which is a backbone of RESTful web services. For example, you can handle a GET method to perform read operations, POST methods to create resources, PUT methods to update resources, and DELETE methods to remove resources from the server.

What is the difference between MVC and Web API?

Web. Http” assembly has all features of MVC but does not have routing, and model binding which are exclusive to Web API. MVC does not either support content negotiation or self-hosting. MVC controller is extremely heavy and we can see the number of interfaces the code uses.


4 Answers

I've done it a few times, I am still using it in production and haven't got any complaints. I actually think its a nice solution because it so simple to setup and maintain. Not this incredibly xml-configuration-heavy wcf stuff..

like image 164
AyKarsi Avatar answered Nov 07 '22 03:11

AyKarsi


You might want to also have a look at the WebAPI stuff that is in the process of being released (.net 4.5):

http://weblogs.asp.net/scottgu/archive/2012/02/23/asp-net-web-api-part-1.aspx

It's very much to do with exposing plain html services.

like image 34
Paddy Avatar answered Nov 07 '22 05:11

Paddy


I would suggest you take a look at ServiceStack: http://www.servicestack.net/. It 's not only quite mature, but it can help you produce cleaner code.

like image 38
Ioannis Karadimas Avatar answered Nov 07 '22 03:11

Ioannis Karadimas


It really does depend on what you plan on doing with your application. Yes, you could write an MVC website that doubles as a RESTful service. However, you are then tying your UI layer very closely to your logic layer, and that is what you really need to consider. I am working on an MVC site with a ServiceStack REST service (already mentioned by @Ioannis) . The reason that I did not make MVC my REST service is because I did not want any changes in my UI to potentially affect any third party application that might be using my logic service. So, as long as you carefully consider the ramifications of making your site also your RESTful service, then either decision could be ok. :)

like image 26
Justin Pihony Avatar answered Nov 07 '22 03:11

Justin Pihony