Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/(dynamic)/environment-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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) }),
),
},
Expand Down
4 changes: 2 additions & 2 deletions content/(dynamic)/zero-runtime.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
},
});
```
Expand Down Expand Up @@ -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.

Expand Down
Loading