Getting Started with Reinhardt

Welcome to Reinhardt! This guide will help you set up your first Reinhardt project and build a simple REST API.

Prerequisites

Before you begin, make sure you have:

  • Rust 1.94.1 or later (2024 Edition required) (Install Rust)
  • PostgreSQL (included in standard and full bundles; optional for custom setups)
  • Basic familiarity with Rust and async programming

Installation

Step 1: Install Reinhardt Admin

cargo install reinhardt-admin-cli

Note: After installation, the command is reinhardt-admin, not reinhardt-admin-cli.

Step 2: Create a New Project

# Create a RESTful API project (default)
reinhardt-admin startproject my-api
cd my-api

This generates a complete project structure:

my-api/
├── .gitignore
├── Cargo.toml
├── Makefile.toml
├── bacon.toml
├── settings/
│   ├── base.toml
│   ├── local.toml
│   ├── staging.toml
│   └── production.toml
├── src/
│   ├── lib.rs
│   ├── apps.rs
│   ├── config.rs
│   ├── bin/
│   │   └── manage.rs
│   └── config/
│       ├── apps.rs
│       ├── settings.rs
│       └── urls.rs
└── README.md

Step 2b: Create a reinhardt-pages Project (Alternative)

For a modern WASM-based frontend with SSR:

# Create a reinhardt-pages project
reinhardt-admin startproject my-app --template-type mtv
cd my-app

# Build WASM and start development server
cargo make dev

This generates a project with 3-layer architecture:

my-app/
├── .gitignore
├── Cargo.toml
├── Makefile.toml
├── bacon.toml
├── build.rs
├── index.html
├── settings/
│   ├── base.example.toml
│   ├── local.example.toml
│   ├── staging.example.toml
│   └── production.example.toml
├── src/
│   ├── lib.rs
│   ├── apps.rs
│   ├── config.rs
│   ├── bin/
│   │   └── manage.rs
│   ├── client.rs
│   ├── client/
│   │   ├── router.rs
│   │   └── state.rs
│   ├── config/
│   │   ├── apps.rs
│   │   ├── settings.rs
│   │   └── urls.rs
│   ├── server/
│   │   └── server_fn.rs
│   ├── shared.rs
│   └── shared/
│       ├── errors.rs
│       └── types.rs
└── README.md

Visit http://127.0.0.1:8000/ in your browser.

Available commands:

  • cargo make dev - Build WASM and start development server
  • cargo make dev-watch - Watch mode with auto-rebuild
  • cargo make build-release - Production binary build
  • cargo make wasm-build-dev - Build WASM only (debug)
  • cargo make wasm-build-release - Build WASM only (release, with wasm-opt)

See examples/examples-twitter for a complete implementation.

Step 3: Choose Your Flavor

Reinhardt comes in three flavors. Choose the one that fits your needs:

Option A: Standard (Balanced) - Default

Balanced setup for most production projects:

# Default behavior - all features enabled
reinhardt = { version = "0.1.0-rc.15", package = "reinhardt-web" }
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }\n```

Includes: Core, Database (PostgreSQL), REST API, Auth, Middleware, Templates

Option B: Full (Everything Included)

reinhardt = { version = "0.1.0-rc.15", package = "reinhardt-web", features = ["full"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }\n```

Includes: Database, Auth, REST API, Admin, GraphQL, WebSockets, Cache, i18n, Mail, Sessions, Static Files, Storage

Option C: Minimal (Lightweight)

For microservices and simple APIs:

reinhardt = { version = "0.1.0-rc.15", package = "reinhardt-web", default-features = false, features = ["minimal"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }\n```

Includes: HTTP, routing, DI, parameter extraction, server

For this guide, we'll use the Standard flavor (default).

💡 Want more control? See the Feature Flags Guide for detailed information on 70+ individual feature flags to fine-tune your build.

The project template already includes all necessary dependencies in Cargo.toml.

Your First API

The generated project already has a working server! Let's customize it.

Step 4: Run the Development Server

# Using cargo-make (recommended)
cargo make runserver

Visit http://127.0.0.1:8000/ in your browser. You should see a welcome message.

Step 5: Create Your First Endpoint

Create an app and add a simple endpoint:

reinhardt-admin startapp hello --template-type restful

Edit hello/views.rs:

use reinhardt::prelude::*;
use reinhardt::get;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct HelloResponse {
    message: String,
}

#[get("/hello", name = "hello_world")]
pub async fn hello_world() -> ViewResult<Response> {
    let response_data = HelloResponse {
        message: "Hello, Reinhardt!".to_string(),
    };
    Ok(Response::ok()
        .with_json(&response_data)?)
}

Register in hello/urls.rs, src/config/urls.rs, and src/config/apps.rs (see project template for examples).

Test: curl http://127.0.0.1:8000/hello

Building a Real API

Create a CRUD API using ViewSets:

reinhardt-admin startapp todos --template-type restful

Define model (todos/models.rs), serializer (todos/serializers.rs), and ViewSet (todos/views.rs):

// todos/views.rs
use reinhardt::ModelViewSet;
use crate::models::Todo;
use crate::serializers::TodoSerializer;

pub fn todo_viewset() -> ModelViewSet<Todo, TodoSerializer> {
    ModelViewSet::new("todo")
}

Register in todos/urls.rs:

use reinhardt::ServerRouter;
use crate::views::todo_viewset;

pub fn url_patterns() -> ServerRouter {
    ServerRouter::new()
        .viewset("/todos", todo_viewset())
}

Then wire it up in config/urls.rs:

use reinhardt::prelude::*;
use reinhardt::UnifiedRouter;
use reinhardt::routes;

// Note: UnifiedRouter requires the `client-router` feature flag.
#[routes]
pub fn routes() -> UnifiedRouter {
    UnifiedRouter::new()
        .mount("/api/", todos::urls::url_patterns())
}

This automatically creates all CRUD endpoints (GET, POST, PUT, DELETE).

Test:

# Create
curl -X POST http://127.0.0.1:8000/api/todos/ \
  -H "Content-Type: application/json" \
  -d '{"title":"Learn Reinhardt","completed":false}'

# List
curl http://127.0.0.1:8000/api/todos/

Project Management Commands

The generated project includes src/bin/manage.rs for Django-style management commands.

Common Commands

# Create a new app
reinhardt-admin startapp myapp --template-type restful

# Development server
cargo make runserver

# Database migrations (when using database features)
# Auto-detects app label if single app has models
cargo make makemigrations

# Or specify app label explicitly (when multiple apps exist)
cargo make makemigrations-app -- <app_label>

# Apply migrations
cargo make migrate

# Check project for issues
cargo make check

# Collect static files
cargo make collectstatic

# Interactive shell
cargo make shell

Note on makemigrations: The command now automatically detects the app label when only one app has registered models. For projects with multiple apps, you must specify the app label explicitly.

Global CLI Tool

You already installed reinhardt-admin in Step 1. Use it for:

# Create new projects
reinhardt-admin startproject myproject

# Create new apps (from project root)
reinhardt-admin startapp myapp

For more details, see the reinhardt-commands documentation.

Next Steps

Congratulations! You've built your first Reinhardt API. Here's what to explore next:

📚 Tutorials

🎛️ Advanced Features

🔌 Database Integration

To use a database instead of in-memory storage:

reinhardt = { version = "0.1.0-rc.15", package = "reinhardt-web", features = ["standard", "db-postgres"] }\n```

Check out the ORM documentation for more details.

Note: Complete working examples are planned for future releases.

Getting Help

Common Issues

Port Already in Use: Change the port in serve() function

Compilation Errors: Ensure Rust 1.94.1+ (rustc --version)

Async Runtime: Add #[tokio::main] to your main function


Happy coding with Reinhardt! 🚀