Skip to main content

Crate krab_core

Crate krab_core 

Source
Expand description

Shared runtime for the Krab full-stack web framework.

The crate root holds the view tree that view! builds and SSR renders — Node, Element, Attribute, EventListener, the Render and IntoNode traits — and the hydration markers that let the browser runtime (krab_client) match server-rendered HTML back to it. The modules cover the rest of a service: configuration and secret sourcing (config), the HTTP stack, database and migration governance, the shared store, telemetry, resilience, signals, render policy, ISR, i18n, WebSockets and server functions.

§Features

There are no default features; much of the crate is behind one:

FeatureEnables
restThe axum HTTP stack: http and its auth, errors, headers, runtime and security modules; server functions
graphqlgraphql, on async-graphql
grpc-semanticsgrpc_semantics: gRPC status codes and grpc-timeout parsing for a gateway — not a gRPC transport
authcredentials: Argon2id password hashing
db-postgresdb with the Postgres runtime and migration governance
db-sqlitedb driver selection with the SQLite driver
redis-storeThe Redis-backed shared store
webBrowser bindings for the wasm32 island runtime

Node is !Send (its Dynamic variant holds an Rc): build and render it inside synchronous code, and do not hold one across an .await.

Modules§

action
Client-initiated async writes with observable state.
config
Environment-driven configuration and the secrets-source policy.
control_flow
Runtime behind view!’s built-in control-flow tags.
credentials
Password credential verification.
csrf
CSRF wire-contract names shared by the server-side protection middleware and the wasm client half of #[server].
db
Database support: driver selection, and the Postgres migration-governance runtime.
error_boundary
Render-time error boundary.
graphql
GraphQL execution with framework policy guards (feature graphql), on top of async-graphql.
grpc_semantics
gRPC semantics for a gateway — not a gRPC transport.
head
Head Management
http
The HTTP surface of krab_core (feature rest), in one import path.
http_auth
Request authentication and authorisation for the rest HTTP stack.
http_error
The JSON error envelope every Krab HTTP surface answers with.
http_headers
Response-header middleware: the fixed security-header set and CORS.
http_runtime
Per-service HTTP runtime state and the health, readiness and metrics handlers that report on it.
http_security
Client-IP extraction and CSRF protection for the HTTP stack.
i18n
Internationalization (i18n)
imageDeprecated
<picture> markup with AVIF/WebP <source>s.
isr
Incremental Static Regeneration (ISR)
layout
Layout System
protocol
Protocol selection: which API protocols (REST, GraphQL, RPC) a service exposes, how they are deployed, and which one a request is served with.
render_policy
A per-route declaration of how a page is rendered, cached, placed and delivered.
render_stream
Streaming SSR: progressive <Suspense> streaming, suspense-boundary markers, and the byte-budgeted chunk writer.
repository
A driver-neutral user-lookup port (features db-postgres or db-sqlite).
resilience
Circuit breaker primitives for outbound resilience.
resource
Client-driven async reads with observable state.
server_fn
Server Functions (#[server])
service
Service bootstrap: a bind configuration and, with feature rest, an axum server loop that shuts down gracefully on SIGINT or SIGTERM.
service_contract
Transport-agnostic service contracts, so one service can call another either in-process or over the network without the caller changing.
signal
Krab reactive signal system.
static_assets
Serving static assets safely.
store
A small key-value store abstraction for state that must be shared between a service’s replicas: rate-limit and auth-failure counters, token revocations, ISR cache entries and render leases.
style_scope
Component-scoped CSS class rewriting.
suspense
Runtime behind view!’s <Suspense> tag.
telemetry
Structured-logging setup: JSON tracing output and the canonical service_started event.
ws
WebSocket Ergonomic Layer

Macros§

collect_server_fns
Collect server function registrations into an array.

Structs§

Attribute
A name="value" attribute of an Element.
Element
An HTML element in the view tree.
EventListener
An event handler attached to an Element (on:click={...} in view!). Only meaningful in the browser.
HydrationNodeMarker
Identifies one element inside a hydration boundary, so the browser can match server-rendered markup to the view tree it rebuilds.

Enums§

Node
A node in the view tree that view! builds.

Constants§

HYDRATION_NODE_ID_ATTR
Attribute that carries an element’s HydrationNodeMarker in rendered HTML: data-krab-node-id="{boundary_id}/{path}".

Traits§

IntoAttributeValue
Conversion of a reactive attribute source’s result into an attribute value; None means the attribute is absent. See Attribute::dynamic.
IntoNode
Conversion into a Node; how expressions interpolated with {...} in view! become part of the tree.
Render
Conversion to an HTML string.

Functions§

annotate_hydration_tree
Stamps a HydrationNodeMarker on every element of node for the boundary boundary_id, starting from the root marker.
next_hydration_boundary_id
A fresh boundary id, {scope}:{n}, with n from a process-wide counter. The #[island] macro calls it once per rendered island, with the island’s name as scope, so ids are unique within a process but not across processes or restarts.

Type Aliases§

DynamicAttributeValue
The source of a reactive attribute: called on the server at render time and in the browser inside an effect, each time the signals it reads change. None means “attribute absent”. See Attribute::dynamic.