ASP.Net MVC or WebAPI?

17

What is the advantage of using MVC and WebAPI (using Visual Studio and C #)?

I think developing in MVC is easier than putting together a form with validations, so just put special attributes for this purpose and use the Wizard that already assembles the form automatically. Does WebAPI not have this feature or am I wrong? When do I use WebAPI and / or MVC?

    
asked by anonymous 02.02.2015 / 14:54

3 answers

25

They are different things, so it is not a matter of being advantageous to use one or the other. They should be used for different purposes. Although they could be used together.

So much so that ASP.NET WebAPI has become an integral part of ASP. NET Core . You no longer use one or the other because essentially they have different operations when you want to do one thing or another, but the basis is the same.

MVC assumes that the user will access sites which are collections of pages to view. WebAPI only returns results, it obviously does not have visions, the V of MVC.

WebAPI has always needed a simpler structure, but if you think about it they need models (the M) and need, if not the controllers (C), something very similar. That's why it makes more sense to use a single framework .

Working with WebAPI is easier for a simple reason, it does a lot less. And this is why if you want to present pages, WebAPI is not an option. At least not alone.

Of course you can use WebAPI to get the results and assemble the pages with different technology. But I doubt that makes any sense to you. You can make third-party consumers your API. For others, understand other programmers or other applications you make.

As the name says WebAPI is to create access APIs in the web format. API is for programmers to consume and how best suits them. It is not for building entire sites.

You can even make the form completely on the client side (type SPA ). I would not need MVC, but this does not work well for sites , works best for applications.

So WebAPI does not assemble a form for you because it's not your goal.

I think in this case you should use MVC.

Or if you're going to do something simpler, consider ASP.NET WebPages . It's curious how hardly anyone knows this. I see many programmers killing themselves to use ASP.NET MVC to make sites very simple simply because they do not know everything that exists in ASP.Net. This technology enables sites in a way that is analogous to pure PHP, using only what is already available by default in the language. WebPages gives an entire infrastructure that helps a lot without imposing a development model.

    
02.02.2015 / 15:14
5

To the bigown answer, which I think is generally correct, I would just like to add that when it says:

  

Of course you can use WebAPI to get the results and assemble the pages with different technology. But I doubt that makes any sense to you. You can make third-party consumers your API.

I would say that it is not true in the situation where it is intended to use AngularJS on the front end. In addition, when it says:

  

API is for programmers to consume and do whatever they want, not to build entire websites.

I would also say that more and more developers are building the entire 'server-side' web-based API (or any other type of web-services). In these cases, the front end is usually drawn using AngularJS.

    
14.09.2015 / 17:41
0

Well, in my humble opinion I agree with bigown, when we are referring to WebAPI, I believe we are unifying a service platform with global access to it.

If you build a layer of services that N different platforms can consult either a web application, or mobile platform, or platforms of different technologies. The fact that you are mounting a form using an MVC application only, you have established a single access to your form and the records are not shared with other platforms.

If you want to expand your access to data globally, a WebAPI framework becomes necessary, thus making it a single, global access, reducing effort in application development.

    
10.09.2015 / 15:43