Variability between property name prefixing #6
-
I'm wanting to discuss property naming mentioned in the following section: https://atlassian.spscommerce.com/wiki/display/SIP/API+-+Naming#APINaming-PropertyNames It mentions rules for when to prefix property names vs when not too. Below is an example:
While this does make the API response look cleaner, I've often experienced that this causes more confusion for the users of the API, in particular for the unique identifier (id in this case). For example, if we were comparing two objects with a foreign key pointing to each other:
In this example, I have no idea looking at the spec what object types item or thing is. If we are doing an equality and if we know that we have a foreign key reference between the two objects (no guarantee from the schema though), looking at the data this example maybe indicates that we should do:
But when in our code editor we often are not looking at the JSON data. We are looking at the properties on the response object for the spec we are given or the object types we have. It is much more clear if the primary identifiers had been fully prefixed out and the properties of both objects match:
Even though
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 15 replies
-
The goal of the existing standards was to provide consistent naming on properties and what they are associated to for not just IDs but for all property types. Are you advocating that "id" is an exception to that rule only? or that ALL properties should have prefixes? I think I prefer that consistency on all properties without the prefix on any, than having an exception for id. I cannot say I have experienced the confusion you have in other APIs that have taken this approach. Even in your example when using Looking at some of our reference APIs, i.e. GitHub API as a good place to start, as its developer experience rep is usually pretty high, their endpoints follow the existing pattern specified in the standards (i.e. using ID). |
Beta Was this translation helpful? Give feedback.
The goal of the existing standards was to provide consistent naming on properties and what they are associated to for not just IDs but for all property types. Are you advocating that "id" is an exception to that rule only? or that ALL properties should have prefixes?
I think I prefer that consistency on all properties without the prefix on any, than having an exception for id. I cannot say I have experienced the confusion you have in other APIs that have taken this approach. Even in your example when using
item.id
that is obvious to me that it is theid
of the object (item). If the variable was poorly named... obviously thats a different issue.Looking at some of our reference APIs, i.e. …