3

I have many Users for every Group. Each User has an array of objects in the following form:

User.groups

[
    {
      "name": "My Group",
      "group_id": "1337xD",
      "is_admin": true
    }
]

As you can see, each User contains a reference to the group they are part of. The application then makes a subsequent request to fetch the group which has a form similar to the following.

Group

{
    "name": "My Group"
    "group_id": "1337xD"
    ...
    "members": [
        {
            (entire User object including User.groups)
        }
    ]

}

I need to be able to access all the Users in the group but each Group doesn't care about what other groups each User is part of, yet that information is returned in the API. Is it good practice to just remove that information when sending all the Users in the Group, or should I keep that information there?

Thanks for any assistance!

  • 2
    I think you already answered your question. We can not say what should be. It depends on the requirements. Your doubt seems to me more likely: should I keep it simple? ;-) – Laiv Dec 19 '16 at 22:53
  • @Laiv yes I'm leaning towards removing that extra information. I was just curious if it was common practice to remove information like this since I want my API to be predictable if it goes public. Anyway, it should be a quick change :) – Carpetfizz Dec 19 '16 at 22:54
  • In such situations I found KISS to be very helpful advice. Or YAGNI – Laiv Dec 19 '16 at 22:59
  • 3
    Just keep in mind that once you've exposed something publicly, you basically have to support it forever. It's far easier to loosen up visibility and add things to an API, but it's nigh impossible to remove things. – RubberDuck Dec 20 '16 at 1:59
2

From your question description it looks like, the consumer of the API doesn't need to know if the groups are linked.

If so, to keep it simple and lean, it is better to remove that extra information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.