Reputation: 41
I had a doubt where should the etag be generated in a REST GET call
My current flow is
initiate GET call
I get the data from the DB
convert the data from the DB into my Object
Return the object to response
my doubt is related to where should the etag be computed
immediately After i get the data from the DB
or after converting the data from the DB to my object structure
Compute on the response object
General guidance is what i seek
Upvotes: 1
Views: 406
Reputation: 7980
The answer to this question will depend on your exact architectural needs. In general, unless your backend business logic necessitates use of the computed ETag, it really only makes sense to generate it in the database layer or in the response.
If your ETag is used by the database system to check for conflicts, then it would be best to compute it there so you can put the functionality in the same place (#1 or maybe #2 depending on where your conversion code is located). If the ETag is being computed merely to return to the user then computing it after you've generated the response is best (#3).
In either case, you should ensure that you compute it and use at the same stage to avoid invalidating your own ETags during data transformations.
Upvotes: 0