简体   繁体   中英

Where should the Etag be computed?

I had a doubt where should the etag be generated in a REST GET call
My current flow is

  1. initiate GET call

  2. I get the data from the DB

  3. convert the data from the DB into my Object

  4. Return the object to response

my doubt is related to where should the etag be computed

  1. immediately After i get the data from the DB

  2. or after converting the data from the DB to my object structure

  3. Compute on the response object

General guidance is what i seek

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM