From db737f4ad6e00e32171755fafc35ba892d46d70a Mon Sep 17 00:00:00 2001 From: Kn0ax Date: Tue, 6 Oct 2026 20:43:39 +0200 Subject: [PATCH] Replace the removed Zero endpoint mode option with readOnly @spacefast/zero 0.5.0 replaced endpoint `mode` with an optional `readOnly`: GET and HEAD read by default, every other method writes. Update the endpoint examples and the endpoint() reference to match. --- content/(dynamic)/environment-variables.mdx | 2 +- content/(dynamic)/zero-runtime.mdx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/content/(dynamic)/environment-variables.mdx b/content/(dynamic)/environment-variables.mdx index b7a2dab2..883c0a75 100644 --- a/content/(dynamic)/environment-variables.mdx +++ b/content/(dynamic)/environment-variables.mdx @@ -98,7 +98,7 @@ import { capsule, endpoint, json } from "@spacefast/zero/server"; export default capsule({ name: "billing", endpoints: { - charge: endpoint({ mode: "write", method: "POST", path: "/api/charge" }, (ctx) => + charge: endpoint({ method: "POST", path: "/api/charge" }, (ctx) => json({ configured: Boolean(ctx.env.STRIPE_SECRET_KEY) }), ), }, diff --git a/content/(dynamic)/zero-runtime.mdx b/content/(dynamic)/zero-runtime.mdx index faef910e..ddfe1fe4 100644 --- a/content/(dynamic)/zero-runtime.mdx +++ b/content/(dynamic)/zero-runtime.mdx @@ -98,7 +98,7 @@ export default capsule({ }), }, endpoints: { - status: endpoint({ mode: "read", method: "GET", path: "/api/status" }, () => text("ok")), + status: endpoint({ method: "GET", path: "/api/status" }, () => text("ok")), }, }); ``` @@ -149,7 +149,7 @@ An action runs without a transaction. It reads the database but cannot write to ### Endpoints -`endpoint(route, handler)` takes `{ method, path, mode }`, where `mode` is `"read"` or `"write"`. Both `method` and `path` must be literal strings, because the compiler reads them from source without running it. The handler gets `(ctx, req)`, where `req` carries `method`, `path`, `url`, `headers`, `query`, and `text()` / `json()` / `bytes()`. +`endpoint(route, handler)` takes `{ method, path, readOnly? }`. `GET` and `HEAD` are read endpoints by default; every other method is a write endpoint. Set `readOnly: true` for a read-only `POST`, or `readOnly: false` for a `GET` that writes. Both `method` and `path` must be literal strings, because the compiler reads them from source without running it. The handler gets `(ctx, req)`, where `req` carries `method`, `path`, `url`, `headers`, `query`, and `text()` / `json()` / `bytes()`. Return one of the response helpers: `json(value)`, `text(value)`, `empty()` for a 204, `redirect(url)` for a 302, or `new ImageResponse(element)` for a rendered 1200x630 image.