PeaLang / Code Library / Blueprint
Production Blueprint · v3.1.36

Enterprise microservice integration

Domain: Enterprise / Service IntegrationHTTPTypeScriptJavaGo
Verified example. The code below was checked against the local PeaLang v3.1.36 parser, interpreter or async VM. It uses only syntax and built-ins present in that source tree.

Problem statement

Several teams consume one policy decision endpoint from different runtimes. Hand-written clients drift from the service contract, so the service must publish generated clients and a health check from the same PeaLang source.

Complete code

let app = web.app()

function health(req) {
  return web.json({"status": "ok", "service": "policy-api"})
}

function invoke(req) {
  return web.json({"accepted": true, "contract": "v1"})
}

app.get("/health", health)
app.post("/v1/invoke", invoke)

let ts = interop.generate_typescript("http://127.0.0.1:8787")
let java = interop.generate_java("http://127.0.0.1:8787")
let go = interop.generate_go("http://127.0.0.1:8787", "pealangclient")
print len(ts) > 0
print len(java) > 0
print len(go) > 0
Save as enterprise-microservice-integration.pea

Run & verify

pea fmt --check enterprise-microservice-integration.pea
pea check enterprise-microservice-integration.pea
pea run enterprise-microservice-integration.pea

# To actually serve the routes (with fastapi extra installed):
# pip install -e ".[fastapi]"
# pea run enterprise-microservice-integration.pea
Always run the formatter and static checker before execution: pea fmt --check enterprise-microservice-integration.pea && pea check enterprise-microservice-integration.pea, then pea run enterprise-microservice-integration.pea (or the host command shown above for async modules).

Why & How

  1. One service object. web.app() creates the router; app.get and app.post register routes. Handlers return web.json(...), giving every consumer the same JSON shape.
  2. Generated contracts. interop.generate_typescript, generate_java and generate_go produce typed client source from one base URL. The snippet checks that each generator returned content; it does not require a running server.
  3. Direction is explicit. These generators create clients that call PeaLang over HTTP — they do not translate PeaLang function bodies into Java, Go or TypeScript. This is the architecture boundary to document for platform teams.
  4. Health first. /health is intentionally tiny and dependency-free, so orchestrators can probe it without triggering policy evaluation or host capabilities.
  5. Contract versioning. The response includes contract: "v1". When the payload changes, bump that field and regenerate clients in the same CI change to avoid silent drift.
  6. Verification. The three true lines prove all client generators produced non-empty output in v3.1.36.