hashira

Crates.iohashira
lib.rshashira
version0.0.2-alpha
sourcesrc
created_at2023-03-30 21:15:11.882356
updated_at2023-05-18 02:36:32.830079
descriptionA server side rendering framework build on top of Yew
homepage
repositoryhttps://github.com/Neo-Ciber94/hashira
max_upload_size
id825728
size300,031
NeoCiber (Neo-Ciber94)

documentation

README

hashira

CI-badge Latest Version Docs

A server side rendering framework built on top of yew.

Getting started

To create a project with hashira you need to install the CLI.

cargo install --force hashira-cli

Creating a new project

Using hashira new you can create a new project, the CLI will prompt you with the template to use, and the project name.

You can also use a shortcut to create a new project:

hashira new --{{template}} --name {{name}}

There are the templates available at the moment:

  • actix-web
  • axum
  • rocket
  • deno

More will be added in the future. Or if you want to create an adapter for your own, look at the code, most of the templates just use an adapter which starts the server, you can check the adapters in /packages/adapters.

This project still on alpha

hashira still on alpha that means:

  • Some features are incomplete
  • Some features may be removed

Features

SSR (Server Side Rendering)

Allow to render your yew components on the server passing down the properties from server side.

async fn render_page(ctx: RenderContext) -> Result<Response> {
    let products = get_products().await?;
    let res = ctx.render_with_props(ProductsPageProps { products }).await;
    Ok(res)
}

#[page_component("/products", render = "render_page")]
fn ProductsPage(props: &ProductsPageProps) -> yew::Html {
    yew::html! {
        // ...
    }
}

Server Actions

Execute code in your server from your components.

struct CreateProduct {
    name: String,
    price: i64,
    description: Option<String>
}

#[action("/api/products/create")]
async fn CreateProductAction(form: Form<CreateProduct>) -> Json<Product> {
    // server side logic
}

#[page_component("/products/add", render = "...")]
fn CreateProductPage() -> yew::Html {
    let action = use_action();

    if action.is_loading() {
        return yew::html! {
            "Creating product..."
        };
    }

    yew::html! {
        <Form<CreateProductAction> action={action.clone()}>
            <input name="name" required={true} />
            <input name="price" required={true} />
            <textarea name="description" rows={4}></textarea>
        </Form<CreateProductAction>>
    }
}

Extractors

Render functions and Server actions allow to inject any parameter that implements FromRequest.

#[action("/api/products/create")]
async fn CreateProductAction(
    form: Form<CreateProduct>,
    headers: HeadersMap,
    method: Method,
    Inject(pool): Inject<MySqlPool>) -> Json<Product> {
    // server side logic
}

Commit count: 477

cargo fmt