Define contracts and handlers
Describe public DTOs independently, then bind handlers and request state on the server.
Declare the public boundary
Put handler-free contracts in a shared module. Zod authoring infers DTO types; execution uses Smoothie's portable JSON Schema validator, not Zod.parse.
// shared/contracts.ts
import { z } from "zod";
import { defineZodEndpointContract } from "@smoothie-framework/service/zod";
export const ReadStatus = defineZodEndpointContract({
operationId: "status.read",
method: "GET",
path: "/api/status",
responses: { 200: z.strictObject({ ready: z.boolean() }) },
});Use closed DTOs to reject accidental fields. Transforms, custom refinements, defaults and coercion are not portable contract rules. Normalize values and check business rules explicitly.
Bind the implementation on the server
// target/server/status.ts
import { defineService } from "@smoothie-framework/service";
import { ReadStatus } from "../../shared/contracts";
export const statusService = defineService({
context: () => ({}),
endpoints: bind => [
bind(ReadStatus, async () => ({
status: 200,
body: { ready: true },
})),
],
});A context provider supplies request-local state. A Service requiring a verified principal needs the host's admission bridge; declaring the input type does not authenticate it.
Next, mount the Service. For body presence and schema limits, see Contracts and JSON validation.