Page History
...
This sample resource object used uses sub-properties because it was assumed that assumes the mailing and shipping parent properties were are unique but each one had require their own (albeit similar) composite properties. Perhaps we need a resource object that allows for one to many any number of addresses. Perhaps we need a resource object that allows users to define the type of addresses. Either or both of these situations are perfect candidates for using sub-resources. Let's start by redesign seeing how the above resource object with would look using sub-resources instead of sub-properties:
Code Block | ||
---|---|---|
| ||
{ "addresses":[ { "type":"Mailing", "address":"PO Box 1234", "city":"New Orleans", "county":"Orleans", "state":"LA", "zip":"70116" }, { "type":"Shipping", "address":"6649 N Blue Gum St", "city":"New Orleans", "county":"Orleans", "state":"LA", "zip":"70116" } ] } |
We see that the mailing and shipping parent properties have been replaced with a single addresses parent property. Furthermore, to properly identify each address sub-resource, a type property has been added and the values of Mailing and Shipping have been assigned to them.