Skip to main content

serve_request

Function serve_request 

Source
pub fn serve_request(
    protocol: &Protocol,
    handler: &WebUIHandler,
    state: Value,
    request: &ServeRequest<'_>,
) -> Result<ServeResponse, String>
Expand description

Handle a server request with automatic route handling.

For HTML requests: renders the full page with route-matched SSR. The handler emits a consolidated window.__webui script block containing state, chain, inventory, and template metadata.

For JSON requests: returns a partial response with route-scoped state, needed templates, and inventory for the webui-router client.

§Arguments

  • protocol — The compiled WebUI protocol from build
  • handler — The WebUI handler (with plugin configured)
  • state — The state JSON to render. For HTML requests, this should be the full app state. For JSON requests, the caller should provide route-scoped state (only what the target page component needs).
  • request — The incoming request details and complete RenderOptions

§Route Parameters

Route parameters (:param in route paths) are automatically extracted and injected into the state object.

§Content Security Policy

Set the response nonce with RenderOptions::with_nonce. Full-document rendering forwards the options unchanged so every generated inline script and the webui-nonce metadata receive the request nonce.