-1

I'm writing a MVC program which downloads the data from an API. I have finished a util class for the http service to receive the data from the API. Now I'm confusing in a MVC framework, should I call the http util method in the Model or Controller?

Alan K
  • 187
  • 2
  • 15

2 Answers2

0

It would make sense if you did it in the Controller part. Model is used to store data. Controller will retrieves data and store it in Model. And then View will display data stored in Model. Hope that my simple explanation could help a little bit

0

I'd implement a separate service class that's used by either by the controller or model to fetch such information. Ealier it was thought that model is about the business logic, so in that sense it would be used by that - nowadays I think having the controller use it would be more common choice.

I think services are a layer of its own, but there are different opinions about it. There's a (closed) discussion "Where do services go in MVC" here which is about that topic.

eis
  • 51,991
  • 13
  • 150
  • 199
  • So the MVC does not strictly define where the network in, it just could not be put in View. – Alan K May 27 '21 at 09:15
  • @AlanK [this discussion](https://softwareengineering.stackexchange.com/a/176673/126417) is probably of relevance to you too. This is no topic short on opinions... :) – eis May 27 '21 at 10:36