Reputation:
I have a system that is built upon MVC5 and also the WebApi. I would like to create a new controller. It's function will be to return API type data in response to a REST request. It will also need to be able to respond as a back-end to a page with buttons where the buttons are used to run some quick process to move data into a table.
I understand that I probably need a WebAPI controller to handle the REST requests but what functionality am I missing out on that comes with the traditional MVC controller?
Upvotes: 0
Views: 88
Reputation: 142014
ApiController
can return a HttpResponseMessage
which correlates directly to a HTTP response as defined by RFC2616.
It can have a payload that contains anything, HTML, XML, JSON, Atom, jpeg, etc.
There is nothing that is allowed in the HTTP specification that you cannot return using an ApiController.
The distinction made by Microsoft between returning "data" and a "view" is one motivated by product placement rather than any technical constraint.
Upvotes: 2
Reputation: 6252
Basically the functionality to render pages, with an api controller you can only return data:
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.
So if you would navigate to an url of an api controller, it would only only display some data, in a specific format (like Json). If you would navigate to an url of a regular controller, it would return a View which you would see as an html page in your browser.
Upvotes: 1