Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

API : MVC or Micro ?

Hi,

I'm currently using Phalcon to build a production API. I started with Micro framework and I was wondering if I should not go with MVC framework who seem to be more structured.

In fact the main problem for me is the routes gestion. To manage routes in my Micro app I have to create (and instantiate, and that is the problem) Collections . But in MVC I dont need render, so I thinks it's pretty too bad to have this loaded.

Can anyone advise me ?

Thanks!

PS: I'm new with Phalcon



5.8k
Accepted
answer
edited Dec '14

You can check out my API solution with phalcon : https://github.com/Atriedes/phalcon-restful-webservice

It uses MVC and annotation routing

How big of an API? If you are talking only a few endpoints then sure, but that is not a maintainable solution for a medium to large setup.

Also, it could be a religious debate on whether to use annotations, either at all or for routing. One camp would say they are configuration and dont belong in code. There is also the issue of now your routing is in each individual controller class, so if you wnted to change your routes you have to refactor multiple classes.

MVC is certainly probably the closest design pattern. There is another thread I just answered with sort of a simliar question. You get into multi-tier applications, onion architecture, having layers in your code, etc.

There is a ton of groundwork stuff to build out to have a "good" base to start with. Figuring out a directory structure and how to organize files is also a learning curve.

Thanks to your comment we go with "standard" Phalcon architecture kind of MC pattern (by disabling view rendering).

Like you say the problem with routing by annotations is the strong link between controller and routing. So we've decide to go with classical routing. Basically we have classes who inherits from \Phalcon\Mvc\Router\Group.

Thanks for your advices :-)