I have a question about the way I am architecting an API. StructureMy API structure so far is like so (there is about 10 classes total, but many are similar, so I've reduced to these classes, and removed fields that are not relevant to the question): Profileid (unique identifier for this Profile)AllergiesX-RaysAllergiesid (unique ID for this allergy)Profile (this points back to the Profile that owns these allergies)name (what they are allergic to)X-Raysid (unique ID for this X-Ray)Profile (points back to the Profile that owns these X-Rays)thumbnail (a compressed version of the X-Ray image)fullImage (the full, uncompressed X-Ray image)Use CasesProfiles are sent down the wire in full, except that in the X-Rays class, the thumbnail is sent instead of the full image. When the user wishes to see the full X-Ray image, then they make another call to download the full image (this is done to save bandwidth, it's possible that a user has 100 X-Rays at 10MB each!). A user can make modifications to Allergies or X-Rays, and these changes would have to be sent back to the server. It'd be wasteful to send the entire Profile object back, so I'd like to send just the individual X-Ray or Allergies object back to the server.ConcernsWhat should my API return (the response format will be JSON) when a user downloads a full profile?{  Profile: {    id: 1234,    Allergies: {       id: 5678,      Profile: {        What goes here? This is a circular reference!         I need to include a reference back to the profile         so I can edit this Allergy client side and push the changes.         Maybe it should be the User ID of the profile,         but I'm not so sure that is a good idea      },      name: peanuts    },    X-Rays: {      id: 3456,      Profile{          ...      },      thumbnail: Base 64 encode of the thumbnail image    }  }}
Dealing with Users and User-Owned Data in an API
architecture;domain model;hibernate