Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/.agent/docs_coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
| Job Queue (Crate) | `crates/rustapi_jobs.md` | `rustapi-jobs` | OK |
| Background Jobs (Recipe) | `recipes/background_jobs.md` | `rustapi-jobs` | OK |
| **Integrations** | | | |
| gRPC | `recipes/grpc_integration.md` | `rustapi-grpc` | NEW |
| SSR | `recipes/server_side_rendering.md` | `rustapi-view` | NEW |
| AI / TOON | `recipes/ai_integration.md` | `rustapi-toon` | NEW |
| gRPC | `recipes/grpc_integration.md` | `rustapi-grpc` | OK |
| SSR | `recipes/server_side_rendering.md` | `rustapi-view` | OK |
| AI / TOON | `recipes/ai_integration.md` | `rustapi-toon` | OK |
| **Learning** | | | |
| Structured Path | `learning/curriculum.md` | N/A | OK |
| **Recipes** | | | |
| File Uploads | `recipes/file_uploads.md` | `rustapi-core` | OK |
| Deployment | `recipes/deployment.md` | `cargo-rustapi` | OK |
| Testing | `recipes/testing.md` | `rustapi-testing` | OK |
4 changes: 2 additions & 2 deletions docs/.agent/last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"last_processed_ref": "v0.1.335",
"date": "2025-02-24",
"notes": "Added Phase 5 (Specialized Skills) to Learning Path, and created recipes for gRPC, SSR, and AI Integration."
"date": "2026-02-15",
"notes": "Fixed critical inaccuracy in SSR recipe. Updated recipes index to be comprehensive. Verified docs coverage."
}
22 changes: 22 additions & 0 deletions docs/.agent/run_report_2026-02-15.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Run Report: 2026-02-15

## 1. Version Detection
- **Target Version:** `v0.1.335`
- **Previous Run:** `v0.1.335` (2025-02-24)
- **Status:** No code changes detected since last run. Proceeding with Continuous Improvement Phase.

## 2. Discovery
- **Date Gap:** Significant time has passed since the last run (almost 1 year).
- **Cookbook Issues:**
- `docs/cookbook/src/recipes/README.md` is outdated and missing many recipe links.
- `docs/cookbook/src/recipes/server_side_rendering.md` contains incorrect instructions (claims auto-configuration that doesn't exist).
- **Docs Coverage:** `rustapi-view` documentation is misleading and needs correction.

## 3. Plan
- **Fix Recipes Index:** Populate `recipes/README.md` with all available recipes.
- **Fix SSR Recipe:** Rewrite the Server-Side Rendering recipe to correctly show manual `Templates` initialization and state injection.
- **Update Coverage:** Mark `rustapi-view` as corrected.

## 4. Improvements
- Aligned documentation with actual code behavior for `rustapi-view`.
- Improved discoverability of recipes by updating the index.
10 changes: 10 additions & 0 deletions docs/cookbook/src/recipes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ Each recipe follows a simple structure:
## Table of Contents

- [Creating Resources](crud_resource.md)
- [Pagination & HATEOAS](pagination.md)
- [JWT Authentication](jwt_auth.md)
- [CSRF Protection](csrf_protection.md)
- [Database Integration](db_integration.md)
- [Testing & Mocking](testing.md)
- [File Uploads](file_uploads.md)
- [Background Jobs](background_jobs.md)
- [Custom Middleware](custom_middleware.md)
- [Real-time Chat](websockets.md)
- [Server-Side Rendering (SSR)](server_side_rendering.md)
- [AI Integration (TOON)](ai_integration.md)
- [Production Tuning](high_performance.md)
- [Resilience Patterns](resilience.md)
- [Time-Travel Debugging (Replay)](replay.md)
- [Deployment](deployment.md)
- [HTTP/3 (QUIC)](http3_quic.md)
- [gRPC Integration](grpc_integration.md)
- [Automatic Status Page](status_page.md)
62 changes: 34 additions & 28 deletions docs/cookbook/src/recipes/server_side_rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Create a `templates` directory in your project root.
<head>
<meta charset="UTF-8">
<title>{% block title %}My App{% endblock %}</title>
<link rel="stylesheet" href="/assets/style.css">
</head>
<body>
<nav>
Expand All @@ -36,7 +35,7 @@ Create a `templates` directory in your project root.
</main>

<footer>
&copy; 2025 RustAPI
&copy; 2026 RustAPI
</footer>
</body>
</html>
Expand Down Expand Up @@ -66,11 +65,11 @@ Create a `templates` directory in your project root.

## Handling Requests

In your `main.rs`, use the `View` type and `Context`.
In your `main.rs`, initialize the `Templates` engine and inject it into the application state. Handlers can then extract it using `State<Templates>`.

```rust,no_run
use rustapi_rs::prelude::*;
use rustapi_view::{View, Context};
use rustapi_view::{View, Templates};
use serde::Serialize;

#[derive(Serialize)]
Expand All @@ -79,35 +78,43 @@ struct User {
is_admin: bool,
}

#[rustapi_rs::get("/")]
async fn index() -> View {
// 1. Create context
let mut ctx = Context::new();

// 2. Insert data
ctx.insert("app_name", "My Awesome App");
#[derive(Serialize)]
struct HomeContext {
app_name: String,
user: User,
items: Vec<String>,
}

let user = User {
name: "Alice".to_string(),
is_admin: true,
#[rustapi_rs::get("/")]
async fn index(templates: State<Templates>) -> View<HomeContext> {
let context = HomeContext {
app_name: "My Awesome App".to_string(),
user: User {
name: "Alice".to_string(),
is_admin: true,
},
items: vec!["Apple".to_string(), "Banana".to_string(), "Cherry".to_string()],
};
ctx.insert("user", &user);

ctx.insert("items", &vec!["Apple", "Banana", "Cherry"]);

// 3. Render template
// RustAPI automatically loads templates from the "templates" directory
View::new("index.html", ctx)
// Render the "index.html" template with the context
View::render(&templates, "index.html", context).await
}

#[tokio::main]
async fn main() {
// No special setup needed for View, it's auto-configured if the crate is present
// and the "templates" directory exists.
let app = RustApi::new().route("/", get(index));
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// 1. Initialize Template Engine
// Loads all .html files from the "templates" directory
let templates = Templates::new("templates/**/*.html")?;

// 2. Add to State
let app = RustApi::new()
.state(templates)
.route("/", get(index));

println!("Listening on http://localhost:3000");
app.run("0.0.0.0:3000").await.unwrap();

Ok(())
}
```

Expand All @@ -119,12 +126,11 @@ In **Release** mode (`cargo run --release`), templates are compiled and cached f

## Asset Serving

To serve CSS, JS, and images, use `ServeDir` from `tower-http` (re-exported or available via `rustapi-extras` if configured, or just standard tower).
To serve CSS, JS, and images, use `serve_static` on the `RustApi` builder.

```rust,ignore
use tower_http::services::ServeDir;

let app = RustApi::new()
.state(templates)
.route("/", get(index))
.nest_service("/assets", ServeDir::new("assets"));
.serve_static("/assets", "assets"); // Serves files from ./assets at /assets
```
Loading