If my WebApi returns a C # ViewModel that converts to a Json ViewModel, then
Yes, absolutely. Thus, you have full control over what is sent to the client. In addition, if you decide to change your basic business models in the new version of your API, for example, you will not break existing customers. All you have to do is adapt the mapping between your business models and your view models.
Or should my WebApi controller return a business object and create a javascript view model?
No, I never sent my business models to a client. You should always use view models.
I have never seen the first in any WebApi tutorial, and I wonder why.
I have never seen the first in any ASP.NET MVC tutorial, and I also wonder why. Probably because the tutorials do not cover real-world application scenarios, but are simplified examples that will allow you to get started with some technologies. This is sad because so many people follow these tutorials without realizing the importance of using presentation models in real-world applications. StackOverflow is a great place to see how many people really donβt know about the importance of viewing models.
source share