In our one-page application, we use an MVC controller (Action methods as API) to run CRUD. What I feel is wrong.
Can someone tell me if this is correct?
For example: -
I have API Controllersay: -
public class MockAPIController : ApiController
{
public ClassA GetSomething(int id)
{
return new ClassA();
}
}
and this can be called from the client side using /api/MockAPI/GetSomething/1. Similarly, if I create an MVC controller, for example: -
public class MockAPIController : Controller
{
public ActionResult GetSomething(int id)
{
return new JsonResult(new ClassA(),JsonRequestBehavior.AllowGet);
}
}
However, I can make it work. Can someone tell me that using an MVC controller for the API is lacking?
EDIT: -
Is it recommended to use MVC controller for API methods? If not, can someone point to its aspect?
user2991761