Booleans without Prefixes #32
-
I often include hints in resource objects. Things like
And yet, if I want to relay those items as actual objects, then In fact, the documentation does not propose how to handle this. It shoes a noun as incorrect ('item'), but then the correct has things like 'active', 'clever', and 'enabled'. I believe without the prefix the intent is not clear. What is the recommendation in situations above? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
@nateklaiber Does it make sense in your scenario to use these guidelines to improve the usefulness of the data communicated? For example: |
Beta Was this translation helpful? Give feedback.
-
@ca0abinary - very good points. I tend to include them both in different scenarios. Counter caches are important. Query methods are important. I include counter caches where necessary (and move to a summary table if there are scoped counter caches). I include query methods as helpful hints. A peek-ahead into the modeling without having to ask the modeling. I do this in server side code as well. I may have things like:
In a server side language, asking My goal in including both is to not bind them together, but also let them serve their purposes. Here's another example for an instance. In this case I have a 'has one' relationship on my resource. Having something like:
Makes more sense to me than:
Which will always be 0 or 1. Again, I treat this as a query method related to the various associations. I find representing them in the API with these prefixes is helpful. |
Beta Was this translation helpful? Give feedback.
-
@nateklaiber - great question. I too have often used these types of prefixes in the past in some APIs I have built. In putting together these standards with our working group, and looking for consistency of usage in our terminology, we found that usage of such prefixes often were shortcuts to more fundamental questions we should be asking about our API contract. If wanting a field like "is_owner", it's often a bit ambiguous in terms of what this owner is (obviously context is important and difficult to talk about in examples without some). If not including the actual "owner" complex object, then including a property name in the contract that more fundamentally describes the owner is encouraged. This should take place with an adjective (something that describes it). You might include an adjective to the "owner" noun (an adjective modifier) to do that effectively: "active_owner" if needed. In terms of convenience properties for collections, the intent is that SDKs or language collection syntax is a preferred location to handle that. |
Beta Was this translation helpful? Give feedback.
-
We have an API with a has_views property that is manually kept in sync with the DB to tell the code if it should even query for views. Comments? |
Beta Was this translation helpful? Give feedback.
@nateklaiber - great question. I too have often used these types of prefixes in the past in some APIs I have built. In putting together these standards with our working group, and looking for consistency of usage in our terminology, we found that usage of such prefixes often were shortcuts to more fundamental questions we should be asking about our API contract.
If wanting a field like "is_owner", it's often a bit ambiguous in terms of what this owner is (obviously context is important and difficult to talk about in examples without some). If not including the actual "owner" complex object, then including a property name in the contract that more fundamentally describes the owner is encou…