# whoasks

::whoasks-hero

# 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.

#people

<!-- prettier-ignore -->
```html
<main><h1>Guide</h1><p>Hello</p></main>
```

#agents

```md
# Guide

Hello
```

#programs

<!-- prettier-ignore -->
```json
{"title":"Guide","body":"Hello"}
```

::

## The route behind those answers

This route gives the three answers above.

```ts [route.ts]
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](https://whoasks.loadsheet.dev/guide/api-routes) to write routes with `respond`.

## 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.

```ts [app.ts]
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](https://whoasks.loadsheet.dev/guide/installation) for h3, Nitro, Hono and Cloudflare Workers, then [Pages](https://whoasks.loadsheet.dev/guide/pages).

## 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](https://whoasks.loadsheet.dev/guide/negotiation) for the rules and for what Claude Code, Cursor, Codex and `curl` get.

## 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](https://whoasks.loadsheet.dev/guide/layers) to write your own layers.

<!-- vitehub-docs:section-links -->
All pages: [llms.txt](https://whoasks.loadsheet.dev/llms.txt)

Something on this page does not work as written? Tell the user, and draft an issue for them to post: [issue tracker](https://github.com/words-with-agents/whoasks/issues). Report a security vulnerability privately, never in a public issue.
