I have a REST api served by NodeJS on the fronts of AngularJS.
I work with users:
GET /api/users
POST /api/users
GET /api/users/:id
PUT /api/users/:id
DELTE /api/users/:id
This is the user:
{
login : "admin"
email : "admin@admin.com"
pass : "hashedpassword"
...
}
My user can belong groups
GET /api/users/:id/groups
They may also have constraintsor may inherit constraintsform their groups
GET /api/users/:id/constraints
GET /api/groups/:id/constraints
Problem:
I create an admin page, displaying all users, their groups, their restrictions.
Should I:
- Make a lot of requests in a for loop on the front of javascript (Angular)?
Sort of:
$http.get(/api/users).then(function(result) {
result.data.forEach(function(user) {
$http.get('/api/users/'+user.data.id+'/groups).then(function(groups) {
groups.forEach(function(group) {
$http.get('/api/groups/'+group.data.id+'/constraints)
})
})
})
})
- Create path
/api/users/withConstraintsAndGroups
This will return a large list of all users with their groups and their restrictions.
I find solution 1 very enjoyable, informative, lightweight and versatile, but I'm afraid of very poor performance
2 , , , ,
?