10

I was told to design an API for a client to manipulate some data. Now, trying to keep up with the Jones', I've designed this using WebAPI. I post to my Restful Webservice an object via $.Ajax

Why is this any different from using the same $.Ajax to post to a standard MVC 4.0 Controller?

What are the advantages?

Thanks

====

With regard to potential answer:

Note If you have worked with ASP.NET MVC, then you are already familiar with controllers. They work similarly in Web API, but controllers in Web API derive from the ApiController class instead of Controller class. The first major difference you will notice is that actions on Web API controllers do not return views, they return data.

====

Wouldn't this still be redundant, after all you can always

return JSON(x);

from any MVC controller.

tereško
  • 58,060
  • 25
  • 98
  • 150
Pinch
  • 4,009
  • 8
  • 40
  • 60
  • 1
    Not really any different if you use MVC's APIController than WebAPI. See this question: http://stackoverflow.com/questions/9494966/difference-between-apicontroller-and-controller-in-asp-net-mvc – Travis J Apr 25 '13 at 19:26
  • Interesting post on this topic here: http://encosia.com/asp-net-web-api-vs-asp-net-mvc-apis/ – Ant P Apr 25 '13 at 19:37

3 Answers3

7

http://encosia.com/asp-net-web-api-vs-asp-net-mvc-apis/

ASP.NET Web API vs. ASP.NET MVC “APIs” by Dave Ward --Thanks Ant P

A beautiful synopsis:

  • Content negotiation
  • Flexibility
  • Separation of concerns
Pinch
  • 4,009
  • 8
  • 40
  • 60
2

MVC is optimized for having a web browser as a client. Web API is more capable of supporting many different clients. IF your only client is a web browser, then MVC is likely going to be a better choice.

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
1

There is no difference in your $.Ajax method. Your web page shouldn't care how the ajax server implements itself, although it does have to be aware if it supports things like oData and what not.

On the server side, there are many differences between them. Certainly, you can create Ajax handlers in MVC, but WebAPI gives you many more tools and more power.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291