Reputation: 1
I want to start implementing a new project for our company, the project is about managing our company’s assets such as server, pc, vehicles, furniture, etc. Main functionalities for the system include:-
So in my project i do not need to have web services as no other system –at this stage- need to integrate with the system. and mainly the controller classes will be returning html pages, but only for some scenarios such as jQuery auto complete the controller class will return JSON object to be displayed on the auto complete . So do i need to use Web API in my case? Or i can implement the system without the need to look into Web API as i did not work on WebAPI before?
Second question , If i assume that i do currently need to use Web API in the current stage; then when i should consider using Web API in my project?
BR
Upvotes: 0
Views: 1672
Reputation: 7135
Since your project requires rendering of html pages then using MVC controllers is preferred since they are optimized for serving content to web browsers.
However, you can mix MVC controllers and Api controllers in the same project. You can put them in separate namespaces, e.g MyApp.Mvc.AssetsController
and MyApp.WebAPI.AssetsController
.
This would let you expose similar URI routes in MVC and WebAPI, eg:
/assets/1 << MVC view - data rendered in html
/api/assets/1 << Web API - Json, images, etc..
In general, if you want someone to be able to consume your API in XML, JSON, etc. then use a web api. If your operations are View-centric (e.g. html pages for user to act on data) then you will want an MVC Controller instead.
Upvotes: 4
Reputation:
See this:Use Controller to render your normal views. ApiController action only return data that is serialized and sent to the client.and this.
Upvotes: 1