hyro

Crates.iohyro
lib.rshyro
version0.3.2
sourcesrc
created_at2023-07-02 03:56:18.791013
updated_at2023-08-09 20:04:56.768263
descriptionHypermedia Rust Orchestration - a refreshing web framework
homepagehttps://github.com/carterisonline/hyro
repositoryhttps://github.com/carterisonline/hyro
max_upload_size
id905848
size45,377
Carter Reeb (carterisonline)

documentation

https://docs.rs/hyro

README

HYRO

noun

/ˈhɪr.oʊ/

HYRO logo HYRO logo
  1. A : acronym for "Hypermedia Rust Orchestration"
    B : a crate that extends Axum with new functionality, like rendering Jinja Templates on the server, bundling css, and a better developer experience.
    C : a powerful HMR framework for hypermedia systems like HTMX.
    D : the equivalent of Rails for nerds

Usage and Examples

  • More in-depth examples can be found at examples/basic and examples/crud. Make sure you cd to the path containing the templates and style folders before running or you will get a file-not-found error!

Let's start with dependencies:

cargo new hyro-getting-started
cargo add hyro
cargo add axum
cargo add tokio -F full
mkdir templates

HYRO templates use Jinja2. Let's start with a basic one:

templates/hello.html.jinja2

<p>Hello, {{ name }}!</p>

Then we can set up our boilerplate:

src/main.rs

use std::borrow::Cow;

use axum::response::Html;
use axum::{routing, Router, Server};
use hyro::{context, RouterExt, Template};

#[tokio::main]
async fn main() {
   let router = Router::new()
      .route("/hello", routing::get(hello))
      .into_service_with_hmr();

   Server::from_tcp(hyro::bind("0.0.0.0:1380").await)).unwrap()
        .serve(router)
        .await
        .unwrap();
}

async fn hello(template: Template) -> Html<Cow<'static, str>> {
   template.render(context! {
      name => "World",
   })
}

Now if we navigate to 'localhost:1380/hello', we can read our message! If you're running in debug mode, you can edit templates/hello.html.jinja2 and the HMR should kick in.

Commit count: 12

cargo fmt