Answer the question
In order to leave comments, you need to log in
How to model REST resources and domain objects?
I am planning an application on Yii2 + Angular2. The server and the front will be different applications that communicate using REST.
0) You need to start with the subject area - I think there are no good alternatives here. It turns out that the subject area falls on the relational model, just one business object can be an abstraction over several tables. Those. the collection of phones in the user model is just his property, an array, as an option, and in the DB view it is the user's table separately and the phone table separately. Relationship by foreign key via JOIN. But something here confuses me. So, I will be grateful for a practical example of creating a subject area.
1) But when I have domain objects - are they also resources in the understanding of REST? Or will they not match, just as domain objects do not match their representation in the database - tables? How to model the subject area and resources for REST with a minimum of unnecessary actions? If someone can write on the example of several entities, it will be great, the theory is very ambiguous.
2) If I have an organized domain on the backend that is deserialized and passed to the client, will this, together with HATEOAS, be the bulk of the domain for an Angular application? Those. I pass some object (resource) and, in addition to it, some actions that the application angular can perform with this resource (it may not perform it, it can add its own, the API does not oblige to anything).
Oh...architecture is about knowing how little you understand....
Answer the question
In order to leave comments, you need to log in
The subject area is a very vague concept. So perhaps we are talking about different things, but still:
All relationships and table structure for REST will not differ much from standard practices. You need to organize everything in such a way that it would be convenient to use it within Yii and ActiveRecords. In the database there are tables user and phones and two models that are interconnected. And $user->phones depending on hasOne or HasMany will be an object or an array of objects. This is the scheme that is optimal for rest with yii2. Requested phones, received phones only or with associated users, requested users, received users with or without phones.
I get the impression that you have a lot of theory in your head, but you've only had a glimpse of yii. Because there is no problem in your problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question