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",
7* Optimisitically types the values we expect in our environment and context:
8*
9* - `Bindings` determines env vars, accessed via `c.env.NAME_OF_VAR` in api handlers
10* - `Variables` determines context vars, accessed via `c.get("NAME_OF_VAR")` in api handlers
11*/
12export type AppType = {
3This is a template for a [HONC](https://honc.dev) project inside ValTown. You should just be able to fork it and get going. It uses:
45- Hono for the API
6- Drizzle for the ORM
7- ValTown sqlite for the DB
8- ValTown as the Cloud
9- Fiberplane as the API Explorer
1011There's a list of example HONC apps for inspiration on GitHub: [here](https://github.com/fiberplane/awesome-honc) and [here](https://github.com/fiberplane/create-honc-app/tree/main/examples)
1import { createFiberplane, createOpenAPISpec } from "./deps/fiberplane.ts";
2import { Hono, HTTPException } from "./deps/hono.ts";
34import homePage from "./app/home.tsx";
5import type { AppType } from "./app/types.ts";
6import usersApi from "./app/users.ts";
7import { db } from "./db/client.ts";
8import { migrateDatabase } from "./db/migrate.ts";
22});
2324/** Mount the user management API at `/api/users` */
25app.route("/api/users", usersApi);
2627/** Render a Home page (example of using Hono with JSX) */
28app.route("/", homePage);
2930/** Create a simplified openapi spec that just lists the routes in our app */
31app.get("/openapi.json", async c => {
32return c.json(
33createOpenAPISpec(app, {
34openapi: "3.0.0",
35info: {
36title: "Honc D1 App",
4243/**
44* Mount the Fiberplane api playground
45* Visit /fp to view the UI
46*/
48"/fp/*",
49createFiberplane({
50openapi: { url: "/openapi.json" },
51}),
52);
63/**
64* Wrap the incoming request, inject the Deno env vars into the Hono app,
65* and then call the Hono api entrypoint (`app.fetch`)
66*/
67export default async function(req: Request): Promise<Response> {
68const env = Deno.env.toObject();
69// NOTE - Adding the entire env object will also expose the following values to your api handlers:
70//
71// * `valtown`
72// * `VAL_TOWN_API_KEY`
73// * `VALTOWN_API_URL`
74//
75// If you don't want those values, remove them from the env object
37</head>
38<body class={bodyStyles}>
39<h1>🪿 Welcome to my HONC API! 🪿</h1>
40<p>
41Visit <a href="/fp" class={linkStyles}>/fp</a> to view the Fiberplane API explorer.
42</p>
43</body>
HONCfiberplane.ts2 matches
1import { createFiberplane, createOpenAPISpec } from "https://esm.sh/@fiberplane/hono@0.4.4";
23export { createFiberplane, createOpenAPISpec };
grandCoralGrousemain.tsx1 match
61const frogAdjectives = [
62"Hopping", "Croaking", "Lily-pad", "Amphibious", "Green",
63"Swampy", "Marsh", "Pond", "Leaping"
64];
65
movieFrogNamermain.tsx1 match
60const frogAdjectives = [
61"Hopping", "Croaking", "Lily-pad", "Amphibious", "Green",
62"Swampy", "Ribbon-tongued", "Marsh", "Pond", "Leaping"
63];
64