diff options
| author | yyamashita <yyamashita@mosquit.one> | 2026-05-14 23:14:49 +0900 |
|---|---|---|
| committer | yyamashita <yyamashita@mosquit.one> | 2026-05-14 23:14:49 +0900 |
| commit | 1c0df5a6eadf20d3dce490b5c5c87a3ee750fe34 (patch) | |
| tree | 7e8dfc88464032c6766c17363473b6d3cc09760b /app/routes/api.events.$id.ts | |
| parent | ca71f49b9cccb8ad83170b123eeaf9a6af7fc684 (diff) | |
Add JSON REST API: GET /api/events, /api/events/:id, /api/venues, /api/openapi.json
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'app/routes/api.events.$id.ts')
| -rw-r--r-- | app/routes/api.events.$id.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/routes/api.events.$id.ts b/app/routes/api.events.$id.ts new file mode 100644 index 0000000..0f0f2e8 --- /dev/null +++ b/app/routes/api.events.$id.ts @@ -0,0 +1,22 @@ +/** + * GET /api/events/:id + */ +import type { Route } from "./+types/api.events.$id"; +import { getEvent } from "~/lib/db.server"; + +export async function loader({ params }: Route.LoaderArgs) { + const id = parseInt(params.id, 10); + if (Number.isNaN(id)) { + return Response.json({ error: "Invalid id" }, { status: 400 }); + } + + const event = getEvent(id); + if (!event) { + return Response.json({ error: "Not found" }, { status: 404 }); + } + + return Response.json( + { event }, + { headers: { "Cache-Control": "public, max-age=300" } } + ); +} |
