Skip to content

Diagram viewer

Scroll to zoom. Drag to pan.

JSON and HTTP

The TypeScript facade accepts native bigint. HTTP and JSON boundaries must use the exported wire codecs where monetary values appear.

import { CheckoutCommandJson, createCheckout } from "@byfungsi/sapa";
import { Effect, Schema } from "effect";
export const decodeAndCreateCheckout = (body: unknown) =>
Schema.decodeUnknownEffect(CheckoutCommandJson)(body, {
onExcessProperty: "error",
}).pipe(Effect.flatMap(createCheckout));

The JSON body uses decimal strings for money. After decoding, SAPA receives native bigint values.

import {
ProductCatalogJson,
seedCatalog,
type ProductCatalog,
} from "@byfungsi/sapa";
import { Effect, Schema } from "effect";
export const decodeAndSeedCatalog = (body: unknown) =>
Schema.decodeUnknownEffect(ProductCatalogJson)(body, {
onExcessProperty: "error",
}).pipe(Effect.flatMap(seedCatalog));
export const encodeCatalog = (catalog: ProductCatalog) =>
Schema.encodeSync(ProductCatalogJson)(catalog);
  • Limit request body size before parsing. Provider notifications are bounded to 1 MiB by the facade, but reject oversized transport bodies earlier.
  • Parse once at the edge and pass decoded values inward.
  • Reject excess properties on commands.
  • Use an authenticated server route for customer and beneficiary identities.
  • Encode through the owning Schema before JSON.stringify.
  • Never install a global bigint JSON serializer.

SAPA does not publish HTTP routes. Your application owns routing, authentication, status codes, CORS, CSRF policy, and rate limiting.