# Introduction to whoasks

A page is written for people. An agent that fetches it gets markup to strip, and a program wants data. whoasks answers each request in the form its reader can use, at the same URL.

## The three forms

A form is a shape an answer can take. Each form has a name, a list of media types, and sometimes an `ext` suffix.

| Form       | For              | Media types                                      | `ext` |
| ---------- | ---------------- | ------------------------------------------------ | ----- |
| `html`     | People, browsers | `text/html`                                      | none  |
| `markdown` | Agents           | `text/markdown`, `text/x-markdown`, `text/plain` | `.md` |
| `json`     | Programs         | `application/json`                               | none  |

A layer can add more forms. See [Add a form](https://whoasks.loadsheet.dev/guide/layers#add-a-form).

## How a request asks

whoasks checks three things in order to make its pick:

1. A twin URL. `/docs/guide.md` asks for the Markdown of `/docs/guide`.
2. `?format=`. `/docs/guide?format=md` asks for the same form. It is for a client that cannot set headers.
3. The `Accept` header. `Accept: text/markdown` asks for Markdown.

When the request states no preference, the answer is the first form the route offers. For a page, that default offer is HTML. See [Negotiation](https://whoasks.loadsheet.dev/guide/negotiation) for all seven rules.

## The pieces

`whoasks()` returns a site with three methods (`ask`, `respond`, and `handle`) plus `forms`.

| Piece                            | What it does                                                                                    |
| -------------------------------- | ----------------------------------------------------------------------------------------------- |
| `whoasks(...layers)`             | Merges the layers and returns a site                                                            |
| `site.handle(request, next)`     | Goes in front of a whole app. Converts its HTML pages to Markdown when a request picks Markdown |
| `site.respond(request, renders)` | Answers one route, from one value per form                                                      |
| `site.ask(request)`              | Returns the pick alone, without building a response                                             |
| `whoasks/h3`                     | `middleware(site)`, which plugs `handle` into an h3 app                                         |
| `whoasks/core`                   | The same `whoasks` with no converter and no imports                                             |
| `mdream(options)`                | The default converter, with your options                                                        |

## Which one you need

| You have                                            | Use                                                      | Page                            |
| --------------------------------------------------- | -------------------------------------------------------- | ------------------------------- |
| A site of HTML pages                                | `handle`, once, in front of the app                      | [Pages](https://whoasks.loadsheet.dev/guide/pages)           |
| A route that returns data                           | `respond` in that route                                  | [API routes](https://whoasks.loadsheet.dev/guide/api-routes) |
| Both                                                | Both. A route that calls `respond` works behind `handle` | [API routes](https://whoasks.loadsheet.dev/guide/api-routes) |
| Your own response code that only needs the decision | `ask`                                                    | [API reference](https://whoasks.loadsheet.dev/reference/api) |
| A content source or a framework to plug in          | A layer                                                  | [Layers](https://whoasks.loadsheet.dev/guide/layers)         |

## What it leaves out

These choices are deliberate:

- It does not read the User-Agent. Two clients with the same `Accept` get the same answer, unless a layer says otherwise.
- `handle` never answers 406. A request that allows nothing offered gets the page as HTML.
- The only adapter in the package is h3. Any other runtime calls `handle` directly.
- No Nuxt module, no `llms.txt` generator, and no agent text format. [Not included](https://whoasks.loadsheet.dev/guide/layers#not-included) shows how to build each.

## Next

Read [Installation](https://whoasks.loadsheet.dev/guide/installation), then [Pages](https://whoasks.loadsheet.dev/guide/pages) for a site or [API routes](https://whoasks.loadsheet.dev/guide/api-routes) for a data route.

<!-- vitehub-docs:section-links -->
## In this section

- [Introduction](https://whoasks.loadsheet.dev/raw/guide.md) (this page)
- [Installation](https://whoasks.loadsheet.dev/raw/guide/installation.md)
- [Pages](https://whoasks.loadsheet.dev/raw/guide/pages.md)
- [API routes](https://whoasks.loadsheet.dev/raw/guide/api-routes.md)
- [Negotiation](https://whoasks.loadsheet.dev/raw/guide/negotiation.md)
- [Layers](https://whoasks.loadsheet.dev/raw/guide/layers.md)

Next: [Installation](https://whoasks.loadsheet.dev/raw/guide/installation.md)

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.
