why?doc

A simple API docs generator for simple APIs.

Usage (example with Hono)

Import:

// (will be published to deno.land/x soon, for now download and import the file)

Initialize:

const doc = WhyDoc({
  title: "Test API Docs",
  basePath: "/api", // optional
})

Then, instead of:

app.get(
  "/test",
  (c) => c.text("test"),
)

Do:

app.get(
  doc("/test", "a simple test"), // returns the path to avoid repeating it
  (c) => c.text("test"),
)

Add GET and POST Parameters:

app.post(
  doc("/abc", "", {
    postParams: {
      name: "string",
    },
  }),
  (c) => c.text("Done!"),
)

app.get(
  doc("/xyz", "returns the 'name' GET parameter", {
    getParams: {
      name: "string",
    },
  }),
  (c) => c.text(c.req.query("name")!),
)

Finally, generate the docs:

genDocs() // optionally, pass in a string path to a different output file
app.use("/docs", serveStatic({ path: "./docs.html" })) // serve the static html file however you want

And get something like:

Screenshot 2023-06-08 at 1 04 29 PM

License

GNU LGPLv3