Crates.io | hashira-tide |
lib.rs | hashira-tide |
version | 0.0.2-alpha |
source | src |
created_at | 2023-05-18 02:59:48.684748 |
updated_at | 2023-05-18 02:59:48.684748 |
description | Tide adapter for hashira |
homepage | |
repository | https://github.com/Neo-Ciber94/hashira |
max_upload_size | |
id | 867385 |
size | 11,280 |
A server side rendering framework built on top of yew.
To create a project with hashira
you need to install the CLI
.
cargo install --force hashira-cli
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:
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
.
hashira
still on alpha that means:
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! {
// ...
}
}
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>>
}
}
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
}