# `CaravelaSvelte.Rest`
[🔗](https://github.com/rsousacode/caravela_svelte/blob/v0.1.0/lib/caravela_svelte/rest.ex#L1)

REST (HTTP-transport) renderer for `CaravelaSvelte`.

Turns a `{name, props}` pair into either a full-document HTML
response (first hit on a URL) or an Inertia-compatible JSON
navigation response (subsequent Inertia-client fetches).

Shares the SSR pipeline with `CaravelaSvelte.Live` via
`CaravelaSvelte.SSR`. Shares no socket/diff machinery: every REST
response carries the full prop payload, because there's no
persistent connection to diff against.

Controllers typically don't call this module directly — they
call `CaravelaSvelte.render/4`, which picks the renderer, runs
SSR, constructs the page object, and sends the right response
shape per the `CaravelaSvelte.Protocol`.

### Scope

Phase B.2 ships:

  * SSR-backed rendering (fires on every non-Inertia first load)
  * Full-document + navigation response shapes
  * Version-mismatch 409 handling

**Deferred** (B.3 and later):

  * `useForm` / `navigate` client helpers
  * SSE real-time (B.4)
  * Partial / lazy / async props (post-1.0)

# `render`

```elixir
@spec render(Plug.Conn.t(), String.t(), map(), keyword()) :: Plug.Conn.t()
```

Render a Svelte component as a REST response. Returns a
`%Plug.Conn{}` ready to send.

## Options

  * `:layout` — a 2-arity function `fn conn, assigns -> iodata end`
    that wraps the data-page `<div>` in an HTML layout. Only used
    on first-load (non-Inertia) responses. When omitted, renders
    a minimal built-in shell that loads `/assets/app.js` and
    `/assets/app.css`.
  * `:version` — override the server's asset version (defaults
    to `CaravelaSvelte.Protocol.asset_version/0`).
  * `:ssr` — set to `false` to skip SSR (useful in dev or tests).
  * `:url` — override the URL stamped on the page object
    (defaults to the conn's request path + query string).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
