Yii2 project architecture restful + web

Hey all.

I am building a new system fra the bottom and up. And I am in the need of restful services, internal services, admin-interfaces etc.

I am starting to understand how Yii2 works and it looks very promising for the project I am building. But there are still a few things I need to have clarified.

I do understand how restful works. There are very good examples of that. And I know how the MVC works. Also good examples.

How would you guys handle the architecture of an application that have both restful services and actions on the same resource? As I understand Yii2, it will give a lot of methods on the controllers, if I need both web-pages and restful services in the same controller.

Usign Yii2 Advanced template, you have many different application that can share same business logic code.

So you will have backend application where you can put controllers and views for administrator; that you will have an application that will work as restful service, with controllers for exposed interfaces, and so on.

Yii2 is well structured to have multiple application that can share same business login (models, components, etc… etc…).

There are lots of ways to skin a REST-ful web service, as you can see: http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html

Havent thought of that. :expressionless: When I read your answer, it was líke … doooh … of course.

But I still have some challenges. The project is going to live in a hosted environment, so I have only one domain active. And I havent read anything on that part yet.

Of what I have understood of applications, its like -> application = domain.

Have I understood that correctly?

If so, then I still dont know how to structure. :) Guess I need to read up on the application documentatiton.

I am planning to use extensions for my development so much of the code will be in there.

Basically I am thinking of using 1 extension to handle all the controllers for restful services and let this extension be the base for models and migrations. Then 1 more extension to handle the webpages. I would gladly have all the views/pages in the same extension as the restful services, but it would give a myriad of controllers hence my question earliere in this thread.

Am I on the right track here ?

Hey jacmoe, you again :)

I havent read all the documentation, but the one yoyu are linking to, I have. I have gone through the application structure.

The reason for asking these questions, is that I think I will end up in more than 100 restful services and a lot of pages using the same models. So I need to structure it right from the beginning.

Difficult question. :)

I think the advanced app template would be a bad choice in this case. Basic or something like it would be better.

I am also thinking that it would be beneficial to let models and other common code reside in the host application rather than in modules/extensions.

Then, perhaps it would be best to let the api be a module with versions as sub-modules, like described in the guide?

I think a REST API of that size deserves to be properly versioned.

Don’t forget to ask this question on StackOverflow and other places too.