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:

    1. 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

    2. web api return json , consumer app handle result in client

questions:

  1. is approach practise?
  2. 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

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -