One URL, the form each reader can use
whoasks looks at each request and answers with HTML, Markdown or JSON. People keep their pages, agents get Markdown, and programs get JSON from the same route.
<main><h1>Guide</h1><p>Hello</p></main># Guide
Hello{"title":"Guide","body":"Hello"}The route behind those answers
Section titled "The route behind those answers"This route gives the three answers above.
import { whoasks } from "whoasks";
const site = whoasks();
const guide = { title: "Guide", body: "Hello" };
export function route(request: Request): Promise<Response> {
return site.respond(request, {
html: () => `<main><h1>${guide.title}</h1><p>${guide.body}</p></main>`,
json: guide,
});
}The keys are the forms the route offers. The first key is the default, so a request that states no preference (curl sends Accept: */*) gets HTML.
There is no markdown key. whoasks makes the Markdown from the HTML with mdream. Read API routes to write routes with respond.
A whole site at once
Section titled "A whole site at once"site.handle(request, next) goes in front of an app. Every HTML page then also answers as Markdown, at the same URL with Accept: text/markdown, at the twin URL /docs/guide.md, and at /docs/guide?format=md.
A browser and a plain curl still get HTML.
import { H3 } from "h3";
import { whoasks } from "whoasks";
import { middleware } from "whoasks/h3";
const site = whoasks();
export const app: H3 = new H3().use(middleware(site));See Installation for h3, Nitro, Hono and Cloudflare Workers, then Pages.
The request decides
Section titled "The request decides"whoasks reads three things in this order: a twin URL, ?format=, then the Accept header. It does not read the User-Agent header, though a layer can.
Read Negotiation for the rules and for what Claude Code, Cursor, Codex and curl get.
Made to be built on
Section titled "Made to be built on"A layer is a plain object passed to whoasks(). It adds a form such as YAML, answers with the Markdown a page was written in, changes the pick, or swaps the converter.
Read Layers to write your own layers.
Built with ViteHub Docs