Readme

Example Hono app with a Fiberplane API explorer.

For an example with OpenApiHono, see: https://www.val.town/x/fiberplane/fiberplaneHonoZodStarter

  1. Import @fiberplane/hono
import { createFiberplane, createOpenAPISpec } from "https://esm.sh/@fiberplane/hono@0.4.4";
  1. Generate a simplified API spec (if you don't already have one)
app.get("/openapi.json", async (c) => { const spec = createOpenAPISpec(app, { info: { title: "My Hono API", version: "1.0.0" }, }); return c.json(spec); });
  1. Mount the api explorer

This will mount it at the root /*, but you can mount it to another route, like /fp/* if you are using / for your main app. We recommend / if your Hono app is an API without a frontend.

app.use( "/*", createFiberplane({ openapi: { url: "/openapi.json" }, }), );
  1. Visit your Val's root route to play with the API explorer!

How it Works

createFiberplane mounts Fiberplane on your app at the specified path, which can be used to explore the api's routes and make requests. Think of it like an embedded, lightweigh postman.

If you don't have an API spec at the ready, then the createOpenAPISpec utility helps create a simple OpenAPI spec from all routes in the application. (Note that this simple spec does not include information on expected query parameters, headers, or payloads!)

Code
HTTP
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
3
stevekrouse avatar

I just ran into a bug that went away when I imported Hono the same way that this code does it. Maybe we should add a note to the installation guide to specify how to import Hono correctly?

fiberplane avatar

oh no way! i just tried with all three of these

  • import { Hono } from "npm:hono@4.7.0";
  • import { Hono } from "jsr:@hono/hono";
  • import { Hono } from "https://esm.sh/hono@4.7.0";

and i was still able to fire off requests. what was the error you were seeing?

i'll put a note in the code + readme to do npm imports for now though

stevekrouse avatar

Thanks! Here's a repro of the bug: https://stevekrouse-honofpbug.web.val.run/fp

Source: https://www.val.town/v/stevekrouse/honoFPBug

The buggy import was import { Hono } from "https://deno.land/x/hono@v3.10.0/mod.ts";

Townie came up with it 🤷‍♂️