⚙️ JSONNET RUNE DIFFICULTY: Apprentice Behavioral

The Strategy of Jsonnet

Encapsulating interchangeable algorithms.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Evocation // Tactic Swapping
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JSONNET PATTERN //
local AuthStrategies = {
  basic: function(req) req + { auth_type: "basic", header: "Basic xyz" },
  oauth2: function(req) req + { auth_type: "oauth2", token: "Bearer abc" }
};

local RequestFactory(strategyName, req) =
  AuthStrategies[strategyName](req);

{
  reqA: RequestFactory("basic", { url: "/api" }),
  reqB: RequestFactory("oauth2", { url: "/secure" })
}

Different calculation algorithms or augmentation logic can be mapped in a dictionary, letting the invoker seamlessly switch tactical maneuvers by name.

Runic Tags: #behavioral #strategy #jsonnet