Skip to content

Quick Start

Build your first REROUTE application in 2 minutes using CLI commands!

Step 1: Install REROUTE

pip install reroute[fastapi]
uv pip install reroute[fastapi]

Step 2: Initialize Your Project

Use the REROUTE CLI to create your project structure automatically:

reroute init my-reroute-app --framework fastapi
cd my-reroute-app

This creates a complete project structure with everything you need:

my-reroute-app/
├── app/
│   ├── __init__.py
│   └── routes/
│       └── __init__.py
├── main.py           # Auto-generated entry point
├── pyproject.toml    # Modern dependency management (v0.1.5+)
├── requirements.txt  # Legacy (will be removed in v0.3.0)
└── .gitignore

Optional but recommended: Install project dependencies:

pip install -r requirements.txt
uv pip install -e .

This ensures all required packages (FastAPI, uvicorn, etc.) are installed for your project.

Modern Python Packaging

Starting with v0.1.5, projects include pyproject.toml for modern dependency management. Use uv for 10-100x faster installations!

Step 3: Generate a Route

Use the CLI to generate your first route:

reroute create route --path /user --name User --methods GET,POST

This creates app/routes/user/page.py with GET and POST methods:

from reroute import RouteBase
from reroute.decorators import rate_limit, cache

class UserRoutes(RouteBase):
    """UserRoutes handles /user endpoints."""

    tag = "User"

    def __init__(self):
        super().__init__()
        self.data = []

    @cache(duration=60)
    def get(self):
        """Handle GET requests - retrieve user"""
        return {
            "users": [
                {"id": 1, "name": "Alice"},
                {"id": 2, "name": "Bob"}
            ]
        }

    @rate_limit("10/min")
    def post(self):
        """Handle POST requests - create new user"""
        return {"message": "User created", "id": 3}

Tip: Edit the generated file to customize the response data!

Step 4: Your Application is Ready!

The reroute init command already created main.py for you:

from fastapi import FastAPI
from reroute.adapters import FastAPIAdapter
from pathlib import Path

app = FastAPI(title="My REROUTE App")

adapter = FastAPIAdapter(
    fastapi_app=app,
    app_dir=Path(__file__).parent / "app"
)
adapter.register_routes()

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

No manual setup required! Everything is configured and ready to run.

Step 5: Run the Application

python main.py

Visit:

Step 6: Test Your API

# Get users
curl http://localhost:8000/user

# Create user
curl -X POST http://localhost:8000/user

Add More Features

Customize Your Generated Routes

The generated route already includes decorators! Edit app/routes/user/page.py to customize:

Rate Limiting

from reroute import RouteBase
from reroute.decorators import rate_limit

class UserRoutes(RouteBase):
    @rate_limit("5/min")  # Limit to 5 requests per minute
    def post(self):
        return {"message": "User created"}

Caching

from reroute import RouteBase
from reroute.decorators import cache

class UserRoutes(RouteBase):
    @cache(duration=60)  # Cache for 60 seconds
    def get(self):
        return {"users": [...]}

Lifecycle Hooks

class UserRoutes(RouteBase):
    def before_request(self):
        print("Authenticating user...")
        return None  # Continue to handler

    def after_request(self, response):
        response["timestamp"] = "2024-01-15T10:30:00Z"
        return response

Next Steps