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
Section titled "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.
How a request asks
Section titled "How a request asks"whoasks checks three things in order to make its pick:
- A twin URL.
/docs/guide.mdasks for the Markdown of/docs/guide. ?format=./docs/guide?format=mdasks for the same form. It is for a client that cannot set headers.- The
Acceptheader.Accept: text/markdownasks 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 for all seven rules.
The pieces
Section titled "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
Section titled "Which one you need"| You have | Use | Page |
|---|---|---|
| A site of HTML pages | handle, once, in front of the app | Pages |
| A route that returns data | respond in that route | API routes |
| Both | Both. A route that calls respond works behind handle | API routes |
| Your own response code that only needs the decision | ask | API reference |
| A content source or a framework to plug in | A layer | Layers |
What it leaves out
Section titled "What it leaves out"These choices are deliberate:
- It does not read the User-Agent. Two clients with the same
Acceptget the same answer, unless a layer says otherwise. handlenever 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
handledirectly. - No Nuxt module, no
llms.txtgenerator, and no agent text format. Not included shows how to build each.
Read Installation, then Pages for a site or API routes for a data route.