I am looking for best practice principle here. As part of my REST Api, I am returning some basic info for a user. Lets say the user can be an "owner" of a company, in which case they have full access to every resource of the company. Or they could have been given delegated access to certain parts of the company. Now I have these two choices of json to return
if user is an owner ...
{
companyId : "123",
companyName: "Acme",
isOwner: true,
delegatedAuthority : null
}
if user has delegated access to certain resources of the company ...
{
companyId : "123",
companyName: "Acme",
isOwner: false,
delegatedAuthority :
{
// An object that provides all the details about the delegation.
}
}
Obviously, from an implementation perspecitive, I would be doing something as simple as setting isOwner = delegatedAuthority == null
behind the scenes.
But should I even returning the flag? From an exploratory or descriptive perspective, it seems like a nice thing to return. Could be helpful for someone building a consumer who might not be familiar with the API or the domain. But for someone familiar with the API/domain, it seems like I might be violating DRY and returning redundant information. Would they now feel compelled to write error checking code to make sure I don't lie to them and return both the isOwner = true
and delegatedAuthority != null
What are the principles you would consider and weigh?