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 };
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>
telegramBotStarterindex.ts1 match
30// This is a no-op if nothing's changed
31if (!isEndpointSet) {
32await bot.api.setWebhook(req.url, {
33secret_token: SECRET_TOKEN,
34});
queryParamsREADME.md1 match
1# Handling query params in requests
23Using the standard [URL#searchParams](https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams) method, you can grab query parameters out of any val that is operating using the [Web API](https://docs.val.town/api/web).
45This val demonstrates how to grab one or more query parameters. It returns the all the query parameters found as a json response.
htmlExampleREADME.md2 matches
1# Returning HTML from the Val Town Web API
23This just lets you use the standard [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object with our [Web API](https://docs.val.town/api/web) to return an HTML response from this Val.
gracefulVioletTunavt3 matches
1export default async function createProject(projectName) {
2const apiToken = Deno.env.get("VAL_TOWN_RW_PROJECTS");
34const response = await fetch("https://api.val.town/v1/projects", {
5method: "POST",
6headers: {
7"Content-Type": "application/json",
8"Authorization": `Bearer ${apiToken}`,
9},
10body: JSON.stringify({