fiberplaneHonoZodStarterREADME.md9 matches
1**Example Hono-Zod-OpenAPI app with a Fiberplane API explorer.**
23> For an example with regular-old Hono, see: https://www.val.town/v/fiberplane/fiberplaneHonoStarter
8```
9102. Expose your OpenAPI spec
11```ts
12app.doc("/doc", {
13openapi: "3.0.0",
14info: {
15title: "User Management API",
16version: "v1.0.0",
17},
19```
20213. Mount the api explorer
2223This will mount it at the root `/*`, but you can mount it to another route, like `/fp/*` if you
24are using `/` for your main app. We recommend `/` if your Hono app is an API without a frontend.
2526```ts
28"/*",
29createFiberplane({
30openapi: { url: "/doc" },
31}),
32);
33```
34354. Visit your Val's root route to play with the API explorer!
3637## How it Works
3839`createFiberplane` mounts Fiberpalne at the root route (`/`), which can be used to explore the api's routes and make requests.
40Think of it like an embedded, lightweight postman.
1import { createRoute, z } from "https://esm.sh/@hono/zod-openapi@0.18.4";
2import { UserSchema } from "../schema.ts";
3
fiberplaneHonoZodStarterindex.ts17 matches
1import { createFiberplane } from "https://esm.sh/@fiberplane/hono@0.4.4";
2import { swaggerUI } from "https://esm.sh/@hono/swagger-ui@0.2.0";
3import { OpenAPIHono } from "https://esm.sh/@hono/zod-openapi@0.18.4";
4import { HTTPException } from "https://esm.sh/hono@4.7.0/http-exception";
56import { createUser, deleteUser, filterUsersByName, findUserById, updateUser } from "./helpers.ts";
7import { superProtectedApi } from "./protected/api.ts";
8import { createUserRoute } from "./routes/create-user.ts";
9import { deleteUserRoute } from "./routes/delete-user.ts";
14import type { AppType } from "./types.ts";
1516const app = new OpenAPIHono<AppType>();
1718app.openapi(getUserRoute, (c) => {
19// This id is coerced to a number by the Zod schema for path parameters
20// See: `UserIdPathParamSchema` in `schema.ts`
30});
3132app.openapi(listUsersRoute, (c) => {
33const { name } = c.req.valid("query");
3438});
3940app.openapi(createUserRoute, (c) => {
41const { name, email, age } = c.req.valid("json");
4246});
4748app.openapi(updateUserRoute, (c) => {
49const { id } = c.req.valid("param");
50const { name, age } = c.req.valid("json");
59});
6061app.openapi(deleteUserRoute, (c) => {
62const { id } = c.req.valid("param");
6373});
7475// Mount an API with bearer auth
76app.route("/protected", superProtectedApi);
7778// Create OpenAPI documentation
79app.doc("/openapi.json", {
80openapi: "3.0.0",
81info: {
82title: "User Management API",
83version: "v1.0.0",
84},
8687// Swagger UI
88app.get("/docs", swaggerUI({ url: "/openapi.json" }));
8990// Mount the Fiberplane UI at the root to be able to test api endpoints
91app.use(
92"/*",
93createFiberplane({
94openapi: { url: "/openapi.json" },
95}),
96);
1import { z } from "https://esm.sh/@hono/zod-openapi@0.18.4";
2import { UserSchema } from "./schema.ts";
3
1import { createRoute } from "https://esm.sh/@hono/zod-openapi@0.18.4";
2import { ErrorSchema, UserIdPathParamSchema, UserSchema } from "../schema.ts";
3
1import { createRoute } from "https://esm.sh/@hono/zod-openapi@0.18.4";
2import { ErrorSchema, UserIdPathParamSchema } from "../schema.ts";
3
1import { createRoute } from "https://esm.sh/@hono/zod-openapi@0.18.4";
2import { ErrorSchema, NewUserSchema, UserIdPathParamSchema, UserSchema } from "../schema.ts";
3
fiberplaneHonoZodStarterapi.ts7 matches
1import { OpenAPIHono } from "https://esm.sh/@hono/zod-openapi@0.18.4";
2import { createRoute } from "https://esm.sh/@hono/zod-openapi@0.18.4";
3import { z } from "https://esm.sh/@hono/zod-openapi@0.18.4";
4import { HTTPException } from "https://esm.sh/hono@4.7.0/http-exception";
5import { ErrorSchema } from "../schema.ts";
6import type { AppType } from "../types.ts";
78export const superProtectedApi = new OpenAPIHono<AppType>();
910// Define a mock route that is protected with bearer auth
3435// Mock middleware that just returns 401 if there's no authorization header for the request
36superProtectedApi.use(async (c, next) => {
37if (!c.req.header("authorization")) {
38return c.json({ error: "Unauthorized" }, 401);
41});
4243superProtectedApi.openapi(superSecretSecretsRoute, c => {
44return c.json({ secrets: ["cold harbor", "other secret idk"] }, 200);
45});
4647superProtectedApi.openAPIRegistry.registerComponent("securitySchemes", "Bearer", {
48type: "http",
49scheme: "bearer",
stevensDemosendDailyBrief.ts8 matches
9798export async function sendDailyBriefing(chatId?: string, today?: DateTime) {
99// Get API keys from environment
100const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
101const telegramToken = Deno.env.get("TELEGRAM_TOKEN");
102106}
107108if (!apiKey) {
109console.error("Anthropic API key is not configured.");
110return;
111}
122123// Initialize Anthropic client
124const anthropic = new Anthropic({ apiKey });
125126// Initialize Telegram bot
162163// disabled title for now, it seemes unnecessary...
164// await bot.api.sendMessage(chatId, `*${title}*`, { parse_mode: "Markdown" });
165166// Then send the main content
169170if (content.length <= MAX_LENGTH) {
171await bot.api.sendMessage(chatId, content, { parse_mode: "Markdown" });
172// Store the briefing in chat history
173await storeChatMessage(
198// Send each chunk as a separate message and store in chat history
199for (const chunk of chunks) {
200await bot.api.sendMessage(chatId, chunk, { parse_mode: "Markdown" });
201// Store each chunk in chat history
202await storeChatMessage(
stevensDemoREADME.md1 match
53You'll need to set up some environment variables to make it run.
5455- `ANTHROPIC_API_KEY` for LLM calls
56- You'll need to follow [these instructions](https://docs.val.town/integrations/telegram/) to make a telegram bot, and set `TELEGRAM_TOKEN`. You'll also need to get a `TELEGRAM_CHAT_ID` in order to have the bot remember chat contents.
57- For the Google Calendar integration you'll need `GOOGLE_CALENDAR_ACCOUNT_ID` and `GOOGLE_CALENDAR_CALENDAR_ID`. See [these instuctions](https://www.val.town/v/stevekrouse/pipedream) for details.