I'm working in a REST JavaScript client, and I'm trying to follow the MVC pattern, but a very basic question came to my mind: who should make the http request and load the data into the model?

My intuition tells me that the controller should do it, but in lots of examples (the ember.js documentation, by example) it's done by the model, with a find() method. But other frameworks, like Django, do it in the controller.

What do you think it's the better way to do this?


A model shouldn't have to worry or even know about persistence. So a model loading itself is out for me.

In MVC: the controller should be the one in control of having the model loaded. Whether it does it itself, or delegates that to a store or repository or whatever other data-persistence service name you can think of is immaterial.


Both can work. I prefer neither. The model loading could be done by some repository or 'store' service.

ExtJs uses Stores which have the knowledge about obtaining model data, provide client side caching etc. I appreciate this design, good separation of concerns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.