Practical Examples

Other examples

Flash messages — all types

pub async fn demo_messages(mut request: Request) -> AppResult<Response> {
    success!(request.notices => "This is a success message.");
    info!(request.notices => "This is an informational message.");
    warning!(request.notices => "This is a warning message.");
    error!(request.notices => "This is an error message.");

    context_update!(request => {
        "title" => "Messages demo",
    });
    request.render("demo.html")
}
{% extends "base.html" %}

{% block content %}
    <h1>{{ title }}</h1>
    {% messages %}
    <p>The messages above come from the flash session.</p>
{% endblock %}

REST API

API routes

pub fn routes() -> Router {
    urlpatterns! {
        "/api/users" => view!{ api_list_users }, name = "api_users",
    }
}

JSON API handler

use axum::Json;
use serde_json::json;

pub async fn api_list_users(request: Request) -> AppResult<Response> {
    let users = users::Entity::find()
        .all(&*request.engine.db)
        .await?;

    Ok(Json(json!({
        "status": "success",
        "count": users.len(),
        "data": users
    })).into_response())
}

Complete base template

<!-- templates/base.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}My App{% endblock %}</title>
    <link rel="stylesheet" href='{% static "css/main.css" %}'>
    {% block extra_css %}{% endblock %}
</head>
<body>
    <header>
        <nav>
            <a href='{% link "index" %}'>Home</a>
            <a href='{% link "about" %}'>About</a>
            <a href='{% link "signup" %}'>Sign up</a>
        </nav>
    </header>

    {% messages %}

    <main>
        {% block content %}{% endblock %}
    </main>

    <footer>
        <p>&copy; 2026 — Powered by Runique</p>
    </footer>

    {% block extra_js %}{% endblock %}
</body>
</html>

Pattern summary

PatternWhen to use
request.render("template.html")Standard HTML rendering
Redirect::to("/").into_response()After a successful action (POST)
context_update!(request => {...})Inject variables into the template
success!(request.notices => "...")Flash message before redirect
flash_now!(error => "...")Immediate message (no redirect)
form.is_valid().awaitValidate a Prisme form
form.save(&db).awaitPersist to the database
form.get_form_mut().database_error(&err)Display a DB error inside the form