Reuse ASP.NET MVC 5 code to build RESTfull Web Api -
cenario
website: asp.net mvc 5 managing models, controllers , views.
api: restful web api managing models, controllers , returning json
the problem: code duplication in bl. redoing same logic in both places.
the approach have in mind:
- take bl out of website mvc , keep in web api in separated vs solution
- the website consumer of web api
about content negotiation, think in 2 options:
web api "knows" format return (viewresult, json or xml) , serialize/deserialize in bl depending of requesting (website, mobile apps, etc.). advantage see keep taking advantage of typed model render view in website
web api return json , consumer app handle result in client
questions:
- is approach practise?
- which better: web api returning json or smart web api "knows" format return?
like @david said, don't need consume web services in mvc controllers. design in such way mvc , api layers "view" business layer. so, in case thinking in terms of visual studio solution, might have data layer project, business layer project , 2 front end projects mvc , api.
Comments
Post a Comment