deterministicKey function

String deterministicKey(
  1. String method,
  2. String path, [
  3. Object? body
])

Compute a deterministic, request-shape-stable idempotency key. Use this instead of a random UUID when the goal is "the same logical request must yield the same result" across crashes / restarts.

Implementation

String deterministicKey(String method, String path, [Object? body]) {
  final text = '$method|$path|${body == null ? '' : jsonEncode(body)}';
  final digest = sha256.convert(utf8.encode(text));
  return digest.toString().substring(0, 32);
}