Drawback of using MVC controllers for web APIs

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
    {
        // GET api/MockAPI/5
        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
    {
        // GET api/MockAPI/5
        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?

+4
4

,

MVC API-. , API-. (, , , , , !)

, -/ , api, MVC-. , , JsonResult ( JSON - ). SPA, API.

, , , , .

0

-API, , .

xml json .

, API :

public ClassA GetSomething(int id)
{

    return new ClassA();
}

xml json - .

+1

Web API HTTP. , HTTP.

-API "" REST.

MVC - HTTP, -. -API , .

+1

ApiControllers , .

ApiControllers REST-ful Apis, .

, , Views, Different Types of ActionResults . , , , ApiControllers.

0

All Articles