Below is a minimal—but fully working—FastAPI “wedding app” that lets you:
- Serve basic event info (date, location)
- Collect RSVPs
- List all guests
You can expand it later with authentication, a real frontend, richer fields, email notifications, etc.
1. Install dependencies
pip install fastapi uvicorn sqlmodel
2. main.py (uses SQLite via SQLModel)
from typing import Optional, List
from fastapi import FastAPI, HTTPException
from sqlmodel import SQLModel, Field, create_engine, Session, select
# --- Models ---
class Guest(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str
email: str
attending: bool
guests_count: int = Field(default=0, ge=0)
message: Optional[str] = None
class EventInfo(SQLModel):
name: str
date: str
location: str
description: Optional[str] = None
# --- App & DB setup ---
DATABASE_URL = "sqlite:///./wedding.db"
engine = create_engine(DATABASE_URL, echo=False)
def create_db_and_tables():
SQLModel.metadata.create_all(engine)
app = FastAPI(
title="Wedding RSVP API",
description="RSVP for our big day! 🎉",
version="1.0"
)
@app.on_event("startup")
def on_startup():
create_db_and_tables()
# --- In‐memory event info ---
EVENT = EventInfo(
name="Alice & Bob’s Wedding",
date="2024-10-05 15:00",
location="Sunset Gardens, Springfield",
description="Join us for a celebration of love, dinner & dancing!"
)
# --- Endpoints ---
@app.get("/", response_model=EventInfo)
def read_event():
"""
Get wedding event details.
"""
return EVENT
@app.post("/rsvp", response_model=Guest, status_code=201)
def create_rsvp(guest: Guest):
"""
Submit your RSVP.
"""
with Session(engine) as session:
# Check for duplicate email
statement = select(Guest).where(Guest.email == guest.email)
existing = session.exec(statement).first()
if existing:
raise HTTPException(400, detail="Email already RSVPed")
session.add(guest)
session.commit()
session.refresh(guest)
return guest
@app.get("/guests", response_model=List[Guest])
def list_guests():
"""
List all RSVPed guests.
"""
with Session(engine) as session:
guests = session.exec(select(Guest)).all()
return guests
@app.get("/guest/{guest_id}", response_model=Guest)
def get_guest(guest_id: int):
"""
Get info on a single guest by ID.
"""
with Session(engine) as session:
guest = session.get(Guest, guest_id)
if not guest:
raise HTTPException(404, detail="Guest not found")
return guest
3. Run the app
uvicorn main:app --reload
4. Example curl
# 1. RSVP
curl -X POST "http://127.0.0.1:8000/rsvp" \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"attending": true,
"guests_count": 2,
"message": "Can’t wait!"
}'
# 2. List guests
curl http://127.0.0.1:8000/guests
Next steps / ideas
- Hook up a React/Vue/HTML frontend
- Add authentication (e.g. invite-code or one-time link)
- Send confirmation emails
- Track meal choices, song requests, hotel accommodations
- Deploy to Heroku/DigitalOcean/AWS
Enjoy your big day—and your new FastAPI app! 🎉