Skip to main content

Creating associated resources before ceatingcreating the main one in a REST setting

Source Link

Creating associated resources before ceating the main one in a REST setting

I'm not sure how common of a scenario this is, but what are some approaches to creating associated entities before you have the actual main entity they're supposed to be linked to? (basically having separate endpoints for the associated & main entity creation, with the associated entities having to be executed first, at least from a UI standpoint)

Take uploading a bunch of documents related to a medical record before the record is saved - where should the documents reside, assuming they're uploaded to some "structured" cloud storage service like AWS S3?

I was considering a temporary storage directory and then moving them to their appropriate location until I realized S3 has no efficient bulk object move method. Furthermore, this also introduces the issue of having to identify 'ghost' documents - documents that were uploaded but never associated with a record.

Another solution would be to save both the documents and the record at the same time, which simplifies things for the API, however, this leads to some performance issues if the client is browser-based and they're uploading a bunch of really large files.

Any other alternatives I'm missing here?