We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

MVC UI with web API in one application?

I found a schema here: https://forum.phalcon.io/discussion/2043/mvc-ui-web-api-example but i still get stuck in how to impliment it.

My app have two parts communicate each other. One is MVC UI like a CRUD application show to visitor. One is API provide to others apps. do you guys have any suggest idea or is there any example?

Your API endpoint doesn't have to be separate from your CRUD application. You can just make a route in your application that outputs content as expected by the API.

For example, you can have these routes for your ordinary application (I don't know what your application does, so this is just an example)


Those would all trigger the appropriate controller, do some work, then output an HTML page. You can simply add a route for your API calls:


These would all trigger a controller and do some work, but they don't have to output HTML - the can output JSON or XML, or whatever you have specificed for your API.