class

Inertia

Inherits Reference < Object

Constants

EMPTY_PROPS = Hash(String, String).new

Constructors

new(version : String, renderer : Renderer)
Source

Instance methods

http_handler

Returns a new HTTP handler for this Inertia instance.

Use this handler in your HTTP server middleware stack. It intercepts the responses from your application and updates them to conform the expected Inertia protocol.

inertia = Inertia.new("1.0.0", MyRenderer.new)

server = HTTP::Server.new([
  HTTP::ErrorHandler.new,
  HTTP::LogHandler.new,
  inertia.http_handler,
])
server.bind_tcp("0.0.0.0", 3000)
server.listen
Source
render(context : HTTP::Server::Context, component : String, props)

Renders a component and serializes its props

This methods handles both initial page loads and subsequent Inertia navigation requests automatically, rendering the props within the HTML renderer or returning simple JSON.

You can use a NamedTuple, a Hash or any instance that responds to JSON serialization (to_json).

inertia.render(
  context,
  component: "Dashboard",
  props: {
    user:   "John",
    unread: 3,
  },
)
Source
render(context : HTTP::Server::Context, component : String)

Renders a component with empty props

Uses current HTTP context to write the response.

Source
version

The asset version is used to detect when frontend assets have changed and force clients to perform a hard refresh.

Ref: https://inertiajs.com/asset-versioning

Source

Nested types