# API reference

> The public API of every Gyral package, generated from the type declarations at build time so it always matches the code.

Source: https://gyral.dev/docs/api/

Each package's page lists everything it exports, entry point by entry point: the declaration as
written in the source (function bodies left out) and its documentation comment. The pages are
generated from the packages this site is built with, every time it's built, so they can't drift
from the code.

> **Writing code? Start from working code, not from the reference.** [Recipes](https://gyral.dev/docs/recipes/)
> has a task list with filters and a signup form, with their tests, and [Forms](https://gyral.dev/docs/forms/)
> opens with a complete validated form. Adapt the closest one and check it; come here to look up
> a name an example or a compiler error shows you. Most of the types are inferred, so you rarely
> write them yourself.

| Package                                  | What's in it                                                                   |
| ---------------------------------------- | ------------------------------------------------------------------------------ |
| [`@gyral/core`](https://gyral.dev/docs/api/core/)         | `define`, commands, subscriptions, stores, forms, the view layer; Vite, ESLint |
| [`@gyral/http`](https://gyral.dev/docs/api/http/)         | `get`, `request`, `submitForm`, the `http` driver; `fakeHttp` for tests        |
| [`@gyral/router`](https://gyral.dev/docs/api/router/)     | `routes`, `listen`, `navigate`, `setHead`, `makeRouter`                        |
| [`@gyral/time`](https://gyral.dev/docs/api/time/)         | `delay`, `debounce`, `every`                                                   |
| [`@gyral/ssr`](https://gyral.dev/docs/api/ssr/)           | `renderPage`, `formAction`, CSP; static generation, Node adapter, dev server   |
| [`@gyral/testing`](https://gyral.dev/docs/api/testing/)   | `step`, `run`, `mount`, `parse`, fake drivers, virtual time, `mountSsr`        |
| [`@gyral/devtools`](https://gyral.dev/docs/api/devtools/) | `mountDevtools` and the panel                                                  |

`@gyral/mcp` (an MCP server for coding agents) and `create-gyral` (the app scaffolder) aren't
in this reference; [Packages](https://gyral.dev/docs/packages/) describes them.

## Reading the reference

- **Types are the contract.** A component is `define<State, Msg, Props, Output>()(tag, spec)`;
  `ComponentSpec` in `@gyral/core` describes every field of `spec`.
- **Helper types are exported.** `Reducer`, `Variant`, `ParseResult` and `StandardSchemaV1`
  (type-only) are the types `Update`, `IntentParser` and the form helpers are
  built from, so a reducer or parser written outside a spec can be typed without copying
  Gyral's definitions.
- **Functions return data.** Command helpers such as `get`, `delay` and `navigate` return a
  `Command`, which does nothing until a reducer returns it.
- **The view layer is Gyral's own.** `html`, `css`, `each`, `keyed`, `raw`, `defineHook` and
  `nothing` are documented with the rest of `@gyral/core`; `@gyral/core/vite` is the preset and
  `@gyral/core/eslint` the template rules. Server rendering is `@gyral/ssr`.

The guides explain how the pieces fit together: start with [Components](https://gyral.dev/docs/components/).
