Using MVC app with WebApi

Hi guys did you recomend any best practices to consume an asp.net webapi from an aspnet mvc app ?

What I whant to do is:

Create an Web Api with my business rules inside it.
One or more asp.net mvc apps that  will consume the web api and work.

So whats the best approach to do it ?

All mvc project referencing the webapi to use the namespace, and the webapi published ?

Independent projects that use each other ? any reference on how to start with ?

Regards,
Diego Garcia

Before using MVC with WebApi, its recommended for you to learn more about basic this applications. Please refer this link to avoid mistake using this application for various purpose :

http://www.asp.net/web-api

First of all thanks @teguhyuliantos, but I’ve alread seen this the articles and videos at this url. 

What I’m asking here its for recommendation on best approaches if it already has any available.

Regards,
Diego Garcia. 

It is my humble opinion, but i am not using much MVC features such as viewbags or modelstates in the projects. In MVC3 i simply write JSonResult controller which passes JSON to the view and adapt the content to it with Javascript. Frontend with who i was
working before prefered it that way and it makes sense to me. Write controllers with returning JSON and it would be easier after to create mobile app or mobile web. I hope it helps :)

Nice tip @PredragPejic I will make some research about it :)

Just some questions, how are you posting changes with that away to work ? are you maping the control names by hand at the view with javascript so it could work as it normaly do ? are you using any javascript framework to do it ? like sencha, kendoui, etc
?

Regards,
Diego Garcia 

Pls follow these links:

1. http://www.infoq.com/news/2013/10/gotober-do-dont-webapi
2. http://devproconnections.com/web-development/restful-api-development-best-practices
3. http://blog.mwaysolutions.com/2014/06/05/10-best-practices-for-better-restful-api/
4. http://www.toptal.com/api-developers/5-golden-rules-for-designing-a-great-web-api
5. https://speakerdeck.com/owolf/web-api-dos-and-donts
6. http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api

For quick summary and navigation of all above best practices from different authors you can visit:

https://curah.microsoft.com/204714/dosdonts-and-best-practices-of-aspnet-web-api

Leave a Reply