Closed oreporan closed 8 years ago
Is it possible to have a filter on a response? That all responses go through this filter? if so - we can have a filter that searches for id's in the response and gets their object....Because its possible for example to return a user, this user has a leagues array, and this array is a list of id's, so we can return everything in one turn
I didn't find the answer for this question, but I found this http://blog.mwaysolutions.com/2014/06/05/10-best-practices-for-better-restful-api/ , which we can implement for future flexability, like version and sorting. Don't know how we can avoid using nouns(1), but we can talk about it.
See 3.4.4 in - http://www.w3.org/TR/mwabp/. So yes, we should send the object. But why th responsibility for this will not be on the models?
There is some good things in the first link, we have done a few - but we need to change our methods to nouns not verbs...it makes sense.
and for the version, I don't understand, what does this give? backwards comp?
Right now our system is built that models don't communicate with other models, only with them selves, and controllers communicate with other controllers/models.
Think about this:
someone calls getLeagueById - This calls the League model, and returns a league object with a users array and a games array. these arrays are just IDs. You want the League model to go through his fields and get all the game objects and user objects? I think its better if the leagues controller does this.... The filter response idea is not good...
It goes even more deep - someone calls getLeagueById, this returns an array of gamesIds, we want to make these in to real objects, so we get the real game objects, but in each game object there is a list of users who are attending this game, also just IDs, so we need to get their objects... its too deep!
Agree, too deep. I think that we still need to let the client decide, if he will ask to see a specific game, we will make anouther http request for this game, let's give only the first level --> league with it's users, maybe only user_id and user_name
if you bring anything more than the user_id then you bring the whole object, its the same...
The more I think about it, the more I think every endpoint response should translate all the Id's (gameId, leagueId, userId) to objects before sending the response.
The other option is that the client-side will get a list of id's (lets say active games ids), and then send another request to translate them. This could cost much more round trips...