Micro Api REST + MVC Backend

Hi all, I'm trying to set up a simple application: I need a backend for editing and an API for remote usage. I'm trying to build the base project using Vokuro and Phalcon REST Boilerplate (https://github.com/redound/phalcon-rest-boilerplate) as base project. I've set up both in the same project, but i can use one or the other changing the index.php file. Vokuro is an MVC bootstrap (configured as a module), the API REST is MICRO, so the bootstrap and the routes are different. At the moment I'm using nginx aliases: every url with /api/ points to api.php (with the micro bootstrap), any other url to index.php (the default MVC). What do you suggest?

edited Mar '19

I've had something similar.

So two separate Phalcon\Mvc\Micro\Collection is the solution which will handle REST API and back-office respectively.

https://docs.phalconphp.com/3.4/en/api/phalcon_mvc_micro_collection

Make sure to divide them by using setPrefix per each collection.



7.4k
edited Mar '19

Make sense. PhalconREST is based on Phalcon\Mvc\Micro\Collection. Do you use Micro collection for backoffice also? I need MVC for that. How have you managed the bootstrap and the routes for both REST API and back-office?

Well, the entire purpose of using MicroCollection is exactly that - you organize your front (user, public) routes and back-office (admin) routes.

I do use same approach for both parts as stated above. You can use MVC as well for back-office or both, I had Volt for views, Models as usual and controllers to glue them as usual.

If you need an example - just ring the bell.



7.4k

An example of how you manage the bootstrap of services, routes and loaders in one place could be usefull.