http_inertia

Types

Deferred prop names grouped by the group that loads them.

pub type DeferredProps =
  List(#(String, List(String)))

Metadata that controls how the client merges props during a visit.

pub type MergeProps {
  MergeProps(
    append: List(String),
    prepend: List(String),
    deep_merge: List(String),
    match_on: List(String),
  )
}

Constructors

  • MergeProps(
      append: List(String),
      prepend: List(String),
      deep_merge: List(String),
      match_on: List(String),
    )

Metadata for a prop that the client should load only once.

pub type OnceProp {
  OnceProp(prop: String, expires_at: option.Option(Int))
}

Constructors

Once-prop metadata keyed by the corresponding prop name.

pub type OnceProps =
  List(#(String, OnceProp))

An Inertia page object returned to the client.

Create a page with page, then use the with_* functions to add optional protocol metadata.

pub type Page {
  Page(
    component: String,
    props: List(#(String, json.Json)),
    version: Version,
    deferred_props: List(#(String, List(String))),
    rescued_props: List(String),
    merge_props: MergeProps,
    scroll_props: List(#(String, ScrollProp)),
    once_props: List(#(String, OnceProp)),
  )
}

Constructors

  • Page(
      component: String,
      props: List(#(String, json.Json)),
      version: Version,
      deferred_props: List(#(String, List(String))),
      rescued_props: List(String),
      merge_props: MergeProps,
      scroll_props: List(#(String, ScrollProp)),
      once_props: List(#(String, OnceProp)),
    )

Pagination metadata for a scrollable prop.

pub type ScrollProp {
  ScrollProp(
    page_name: String,
    previous_page: option.Option(Int),
    next_page: option.Option(Int),
    current_page: Int,
  )
}

Constructors

Scroll metadata keyed by the corresponding prop name.

pub type ScrollProps =
  List(#(String, ScrollProp))

The asset version included in an Inertia page object.

pub type Version {
  StringVersion(String)
  NullVersion
}

Constructors

  • StringVersion(String)

    A concrete asset version string.

  • NullVersion

    No asset version. This is encoded as JSON null.

Values

pub fn app_script(
  url: String,
  page: Page,
) -> List(element.Element(msg))

Renders the initial Inertia application elements.

The result contains the #app mount element and a JSON script element with the initial page data for the client to read.

pub fn empty_merge_props() -> MergeProps

Returns merge metadata with every prop list empty.

pub fn header(
  req: request.Request(connection),
  key: String,
) -> option.Option(String)

Looks up a request header case-insensitively.

Returns None when the header is absent.

pub fn header_csv(
  req: request.Request(connection),
  key: String,
) -> List(String)

Splits a comma-separated request header into trimmed, non-empty values.

Returns an empty list when the header is absent or has no values.

pub fn is_inertia_request(
  req: request.Request(connection),
) -> Bool

Returns True when req includes X-Inertia: true.

pub fn is_partial_reload_for(
  req: request.Request(connection),
  component: String,
) -> Bool

Returns True when req is a partial reload for component.

pub fn merge_props(
  append append: List(String),
  prepend prepend: List(String),
  deep_merge deep_merge: List(String),
  match_on match_on: List(String),
) -> MergeProps

Creates metadata that controls how the client merges the specified props.

Each list contains prop paths understood by the Inertia client.

pub fn once_prop(
  prop prop: String,
  expires_at expires_at: option.Option(Int),
) -> OnceProp

Creates metadata for a prop the client should load only once.

expires_at is a Unix timestamp and is encoded as JSON null when absent.

pub fn page(
  component component: String,
  props props: List(#(String, json.Json)),
  version version: Version,
) -> Page

Creates an Inertia page with no optional protocol metadata.

Use the with_* functions to add deferred, merge, scroll, rescued, or once-prop metadata.

pub fn page_component_json(url: String, page: Page) -> json.Json

Encodes a page object in the JSON shape required by the Inertia protocol.

Empty optional metadata is omitted from the returned object.

pub fn request_url(req: request.Request(connection)) -> String

Returns the request path with its encoded query string when one is present.

If the query string cannot be parsed, this returns the path alone.

pub fn scroll_prop(
  page_name page_name: String,
  previous_page previous_page: option.Option(Int),
  next_page next_page: option.Option(Int),
  current_page current_page: Int,
) -> ScrollProp

Creates pagination metadata for a scrollable prop.

previous_page and next_page are encoded as JSON null when absent.

pub fn should_include_prop(
  req: request.Request(connection),
  component: String,
  key: String,
) -> Bool

Returns whether a prop should be included in the response.

Props are included for full visits. For partial reloads, the X-Inertia-Partial-Data and X-Inertia-Partial-Except headers determine whether key is included; except takes precedence over only.

pub fn should_skip_once_prop(
  req: request.Request(connection),
  component: String,
  prop_name: String,
  once_key: String,
) -> Bool

Returns whether an already-loaded once prop should be omitted from a response.

The decision uses X-Inertia-Except-Once-Props and, for partial reloads, the partial-data and partial-except headers.

pub fn with_deferred_props(
  page: Page,
  deferred_props: List(#(String, List(String))),
) -> Page

Returns page with its deferred-prop metadata replaced by deferred_props.

pub fn with_merge_props(
  page: Page,
  merge_props: MergeProps,
) -> Page

Returns page with its merge metadata replaced by merge_props.

pub fn with_once_props(
  page: Page,
  once_props: List(#(String, OnceProp)),
) -> Page

Returns page with its once-prop metadata replaced by once_props.

pub fn with_rescued_props(
  page: Page,
  rescued_props: List(String),
) -> Page

Returns page with its rescued deferred-prop names replaced by rescued_props.

pub fn with_scroll_props(
  page: Page,
  scroll_props: List(#(String, ScrollProp)),
) -> Page

Returns page with its scroll metadata replaced by scroll_props.

Search Document