Inertia.js implementations for Rust. Currently supports Rocket.

Overview

Inertia.rs

Current Crates.io Version Build Status docs.rs

Inertia.js implementations for Rust. Currently supports Rocket.

Why Inertia?

From inertiajs.com

Inertia is a new approach to building classic server-driven web apps. We call it the modern monolith.

Inertia allows you to create fully client-side rendered, single-page apps, without much of the complexity that comes with modern SPAs. It does this by leveraging existing server-side frameworks.

Inertia has no client-side routing, nor does it require an API. Simply build controllers and page views like you've always done!

Inertia.rs brings a straightforward integration to Rust.

Installation

Add the following line to your Cargo.toml

inertia_rs = { version = "0.2.0", features = ["rocket"] }

Usage

inertia_rs defines a succinct interface for creating Inertia.js apps in Rocket. It's comprised of two elements,

  • Inertia

    a Responder that's generic over T, the Inertia component's properties

  • VersionFairing

    Responsible for asset version checks. Constructed via VersionFairing::new, which is given the asset version and a closure responsible for generating the Inertia's HTML template.

Sample Rocket Server

Inertia { Inertia::response( // the component to render "hello", // the props to pass our component Hello { some_property: "hello world!".into() }, ) } #[launch] fn rocket() -> _ { rocket::build() .mount("/", routes![hello]) .attach(Template::fairing()) // Version fairing is configured with current asset version, and a // closure to generate the html template response // `ctx` contains `data_page`, a json-serialized string of // the inertia props .attach(VersionFairing::new("1", |request, ctx| { Template::render("app", ctx).respond_to(request) })) } ">
#[macro_use]
extern crate rocket;

use inertia_rs::rocket::{Inertia, VersionFairing};
use rocket::response::Responder;
use rocket_dyn_templates::Template;

#[derive(serde::Serialize)]
struct Hello {
    some_property: String,
}

#[get("/hello")]
fn hello() -> Inertia {
    Inertia::response(
        // the component to render
        "hello",
        // the props to pass our component
        Hello { some_property: "hello world!".into() },
    )
}

#[launch]
fn rocket() -> _ {
    rocket::build()
        .mount("/", routes![hello])
        .attach(Template::fairing())
        // Version fairing is configured with current asset version, and a 
        // closure to generate the html template response
        // `ctx` contains `data_page`, a json-serialized string of 
        // the inertia props
        .attach(VersionFairing::new("1", |request, ctx| {
            Template::render("app", ctx).respond_to(request)
        }))
}
You might also like...
Sōzu HTTP reverse proxy, configurable at runtime, fast and safe, built in Rust. It is awesome! Ping us on gitter to know more

Sōzu · Sōzu is a lightweight, fast, always-up reverse proxy server. Why use Sōzu? Hot configurable: Sozu can receive configuration changes at runtime

A Rust application which funnels external webhook event data to an Urbit chat.
A Rust application which funnels external webhook event data to an Urbit chat.

Urbit Webhook Funnel This is a simple Rust application which funnels external webhook event data to an Urbit chat. This application is intended to be

A html document syntax and operation library written in Rust, use APIs similar to jQuery.

Visdom A server-side html document syntax and operation library written in Rust, it uses apis similar to jQuery, left off the parts thoes only worked

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

Starlight is a JS engine in Rust which focuses on performance rather than ensuring 100% safety of JS runtime.

starlight Starlight is a JS engine in Rust which focuses on performance rather than ensuring 100% safety of JS runtime. Features Bytecode interpreter

A rust web framework with safety and speed in mind.

darpi A web api framework with speed and safety in mind. One of the big goals is to catch all errors at compile time, if possible. The framework uses

A web framework for Rust.

Rocket Rocket is an async web framework for Rust with a focus on usability, security, extensibility, and speed. #[macro_use] extern crate rocket; #[g

Rust / Wasm framework for building client web apps
Rust / Wasm framework for building client web apps

Yew Rust / Wasm client web app framework Documentation (stable) | Documentation (latest) | Examples | Changelog | Roadmap | 简体中文文档 | 繁體中文文檔 | ドキュメント A

问卷反馈收集, 前端脚手架安装向导, rust, gtk3, win32, dll
问卷反馈收集, 前端脚手架安装向导, rust, gtk3, win32, dll

scaffold-wizard 这是一款加持了【图形用户界面】的npm - inquirer(名曰:问卷)。即,根据【问卷】配置文件,以人-机交互的形式,收集终端用户的【回答结果】。这里提到的【问卷配置】与【回答结果】都是*.json格式的字符串(或文件)。 【问卷】既能够作为.exe文件被双击运行

Owner
Stuart Hinson
Stuart Hinson
Bare-metal software for the sounding rocket payload.

CanSat Software for the sounding rocket payload. Prerequisites cargo-make cargo-embed - Requires libusb, see cargo-embed's README.md for instructions.

COSMO PK Group 2 Dec 19, 2022
Tools that parsing Rust code into UML diagram (in dot format currently).

rudg Rust UML Diagram Generator Tools that parsing Rust code into UML diagram (in dot format currently). Usage $ rudg.exe --help rudg 0.1.0 USAGE:

Zhai Yao 16 Nov 13, 2022
Rust Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.

Rust Embed Rust Custom Derive Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev. Y

Peter 1k Jan 5, 2023
Rust I18n is use Rust codegen for load YAML file storage translations on compile time, and give you a t! macro for simply get translation texts.

Rust I18n Rust I18n is use Rust codegen for load YAML file storage translations on compile time, and give you a t! macro for simply get translation te

Longbridge 73 Dec 27, 2022
lispr is a Rust macro that tries to implement a small subset of LISPs syntax in Rust

lispr lispr is a Rust macro that tries to implement a small subset of LISPs syntax in Rust. It is neither especially beautiful or efficient since it i

Jan Vaorin 0 Feb 4, 2022
Rust/Axum server implementation with PCR(Prisma Client Rust)

Realworld Rust Axum Prisma This project utilizes Rust with the Axum v0.7 framework along with the Prisma Client Rust to build a realworld application.

Neo 3 Dec 9, 2023
A Rust web framework

cargonauts - a Rust web framework Documentation cargonauts is a Rust web framework intended for building maintainable, well-factored web apps. This pr

null 179 Dec 25, 2022
A Rust library to extract useful data from HTML documents, suitable for web scraping.

select.rs A library to extract useful data from HTML documents, suitable for web scraping. NOTE: The following example only works in the upcoming rele

Utkarsh Kukreti 829 Dec 28, 2022
openapi schema serialization for rust

open api Rust crate for serializing and deserializing open api documents Documentation install add the following to your Cargo.toml file [dependencies

Doug Tangren 107 Dec 6, 2022
📮 An elegant Telegram bots framework for Rust

teloxide A full-featured framework that empowers you to easily build Telegram bots using the async/.await syntax in Rust. It handles all the difficult

teloxide 1.6k Jan 3, 2023